ZQuest Classic Coverage Report


Directory: src/
File: src/zc/zc_sys.cpp
Date: 2024-09-12 17:48:44
Exec Total Coverage
Lines: 1937 4475 43.3%
Functions: 136 332 41.0%
Branches: 1301 3726 34.9%

Line Branch Exec Source
1 #include "zc/zc_sys.h"
2
3 #include "allegro/gfx.h"
4 #include "allegro5/joystick.h"
5 #include "base/files.h"
6 #include "base/render.h"
7 #include "zalleg/zalleg.h"
8 #include "base/qrs.h"
9 #include "base/dmap.h"
10 #include <functional>
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <cstring>
14 #include <math.h>
15 #include <map>
16 #include <filesystem>
17 #include <ctype.h>
18 #include <sstream>
19 #include "base/version.h"
20 #include "base/zc_alleg.h"
21 #include "gamedata.h"
22 #include "zc/replay_upload.h"
23 #include "zc/zc_init.h"
24 #include "init.h"
25 #include "zc/replay.h"
26 #include "zc/cheats.h"
27 #include "zc/render.h"
28 #include "base/zc_math.h"
29 #include "base/zapp.h"
30 #include "dialog/cheatkeys.h"
31 #include "metadata/metadata.h"
32 #include "zc/zelda.h"
33 #include "zc/saves.h"
34 #include "tiles.h"
35 #include "base/colors.h"
36 #include "pal.h"
37 #include "base/zsys.h"
38 #include "base/qst.h"
39 #include "zc/zc_sys.h"
40 #include "play_midi.h"
41 #include "gui/jwin_a5.h"
42 #include "base/jwinfsel.h"
43 #include "base/gui.h"
44 #include "midi.h"
45 #include "subscr.h"
46 #include "zc/maps.h"
47 #include "sprite.h"
48 #include "zc/guys.h"
49 #include "zc/hero.h"
50 #include "zc/title.h"
51 #include "particles.h"
52 #include "sound/zcmusic.h"
53 #include "zconsole.h"
54 #include "zc/ffscript.h"
55 #include "dialog/info.h"
56 #include "dialog/alert.h"
57 #include "zc/combos.h"
58 #include "zc/jit.h"
59 #include "zc/zc_subscr.h"
60 #include <fmt/format.h>
61 #include "zconsole/ConsoleLogger.h"
62 #include "zinfo.h"
63 #include "base/misctypes.h"
64 #include "music_playback.h"
65 #include <base/new_menu.h>
66 #include <base/files.h>
67
68 #ifdef __EMSCRIPTEN__
69 #include "base/emscripten_utils.h"
70 #endif
71
72 using namespace std::chrono_literals;
73
74 extern bool Playing;
75 int32_t sfx_voice[WAV_COUNT];
76 int32_t d_stringloader(int32_t msg,DIALOG *d,int32_t c);
77 int32_t d_midilist_proc(int32_t msg,DIALOG *d,int32_t c);
78
79 static ALLEGRO_JOYSTICK* gamepad_dlg_cur_joystick;
80 static int32_t d_joylist_proc(int32_t msg,DIALOG *d,int32_t c);
81
82 extern byte monochrome_console;
83
84 extern HeroClass Hero;
85 extern zcmodule moduledata;
86 extern sprite_list guys, items, Ewpns, Lwpns, chainlinks, decorations;
87 extern particle_list particles;
88 extern int32_t loadlast;
89 extern char *sfx_string[WAV_COUNT];
90 byte use_dwm_flush;
91 byte use_save_indicator;
92 int32_t paused_midi_pos = 0;
93 byte midi_suspended = 0;
94 byte zc_192b163_warp_compatibility;
95 char modulepath[2048];
96 bool epilepsyFlashReduction;
97 signed char pause_in_background_menu_init = 0;
98 byte pause_in_background = 0;
99 bool is_sys_pal = false;
100 static bool load_control_called_this_frame;
101 extern PALETTE* hw_palette;
102 extern bool update_hw_pal;
103 extern const char* dmaplist(int32_t index, int32_t* list_size);
104 int32_t getnumber(const char *prompt,int32_t initialval);
105
106 extern bool kb_typing_mode; //script only, for disbaling key presses affecting Hero, etc.
107 extern int32_t cheat_modifier_keys[4]; //two options each, default either control and either shift
108
109 static const char *qst_module_name = "current_module";
110 #ifdef ALLEGRO_LINUX
111 static const char *samplepath = "samplesoundset/patches.dat";
112 #endif
113 char qst_files_path[2048];
114
115 extern TopMenu the_player_menu;
116 #ifdef _MSC_VER
117 #define getcwd _getcwd
118 #endif
119
120 bool rF11();
121 bool rI();
122 bool rQ();
123 bool zc_key_pressed();
124
125 #ifdef _WIN32
126
127 // This should only be necessary for MinGW, since it doesn't have a dwmapi.h. Add another #ifdef if you like.
128 extern "C"
129 {
130 typedef HRESULT(WINAPI *t_DwmFlush)();
131 typedef HRESULT(WINAPI *t_DwmIsCompositionEnabled)(BOOL *pfEnabled);
132 }
133
134 void do_DwmFlush()
135 {
136 static HMODULE shell = LoadLibrary("dwmapi.dll");
137
138 if(!shell)
139 return;
140
141 static t_DwmFlush flush=reinterpret_cast<t_DwmFlush>(GetProcAddress(shell, "DwmFlush"));
142 static t_DwmIsCompositionEnabled isEnabled=reinterpret_cast<t_DwmIsCompositionEnabled>(GetProcAddress(shell, "DwmIsCompositionEnabled"));
143
144 BOOL enabled;
145 isEnabled(&enabled);
146
147 if(isEnabled)
148 flush();
149 }
150
151 #endif // _WIN32
152
153 239 void zc_exit(int code)
154 {
155 extern CConsoleLoggerEx zscript_coloured_console;
156
157
1/2
✓ Branch 0 taken 239 times.
✗ Branch 1 not taken.
239 if (replay_get_mode() == ReplayMode::Record) replay_save();
158 239 replay_stop();
159 239 music_stop();
160 239 kill_sfx();
161
162
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 224 times.
239 if (get_qr(qr_OLD_SCRIPT_VOLUME))
163 {
164 //restore user volume settings
165
2/2
✓ Branch 0 taken 223 times.
✓ Branch 1 taken 1 times.
224 if (FFCore.coreflags & FFCORE_SCRIPTED_MIDI_VOLUME)
166 {
167 1 master_volume(-1, ((int32_t)FFCore.usr_midi_volume));
168 1 }
169
2/2
✓ Branch 0 taken 223 times.
✓ Branch 1 taken 1 times.
224 if (FFCore.coreflags & FFCORE_SCRIPTED_DIGI_VOLUME)
170 {
171 1 master_volume((int32_t)(FFCore.usr_digi_volume), 1);
172 1 }
173
2/2
✓ Branch 0 taken 223 times.
✓ Branch 1 taken 1 times.
224 if (FFCore.coreflags & FFCORE_SCRIPTED_MUSIC_VOLUME)
174 {
175 1 emusic_volume = (int32_t)FFCore.usr_music_volume;
176 1 }
177
1/2
✓ Branch 0 taken 224 times.
✗ Branch 1 not taken.
224 if (FFCore.coreflags & FFCORE_SCRIPTED_SFX_VOLUME)
178 {
179 sfx_volume = (int32_t)FFCore.usr_sfx_volume;
180 }
181 224 }
182
1/2
✓ Branch 0 taken 239 times.
✗ Branch 1 not taken.
239 if ( FFCore.coreflags&FFCORE_SCRIPTED_PANSTYLE )
183 {
184 pan_style = (int32_t)FFCore.usr_panstyle;
185 }
186 239 save_game_configs();
187
188 239 zscript_coloured_console.kill();
189 239 jit_shutdown();
190 239 quit_game();
191
192 239 Z_message("ZQuest Classic web site: https://zquestclassic.com\n");
193 239 Z_message("ZQuest Classic old wiki: https://web.archive.org/web/20210910193102/https://zeldaclassic.com/wiki\n");
194 239 Z_message("ZQuest Classic new wiki: https://github.com/ZQuestClassic/ZQuestClassic/wiki\n");
195
196 239 allegro_exit();
197 239 exit(code);
198 }
199
200 92829 bool flash_reduction_enabled(bool check_qr)
201 {
202
4/4
✓ Branch 0 taken 88404 times.
✓ Branch 1 taken 4425 times.
✓ Branch 2 taken 87576 times.
✓ Branch 3 taken 92001 times.
92829 return (check_qr && get_qr(qr_EPILEPSY)) || epilepsyFlashReduction || replay_is_debug();
203 }
204
205 // Dialogue largening
206 void large_dialog(DIALOG *d)
207 {
208 large_dialog(d, 1.5);
209 }
210
211 void large_dialog(DIALOG *d, float RESIZE_AMT)
212 {
213 if(!d[0].d1)
214 {
215 d[0].d1 = 1;
216 int32_t oldwidth = d[0].w;
217 int32_t oldheight = d[0].h;
218 int32_t oldx = d[0].x;
219 int32_t oldy = d[0].y;
220 d[0].x -= int32_t(d[0].w/RESIZE_AMT);
221 d[0].y -= int32_t(d[0].h/RESIZE_AMT);
222 d[0].w = int32_t(d[0].w*RESIZE_AMT);
223 d[0].h = int32_t(d[0].h*RESIZE_AMT);
224
225 for(int32_t i=1; d[i].proc !=NULL; i++)
226 {
227 // Place elements horizontally
228 double xpc = ((double)(d[i].x - oldx) / (double)oldwidth);
229 d[i].x = int32_t(d[0].x + (xpc*d[0].w));
230
231 if(d[i].proc != d_stringloader)
232 {
233 if(d[i].proc==d_bitmap_proc)
234 {
235 d[i].w *= 2;
236 }
237 else d[i].w = int32_t(d[i].w*RESIZE_AMT);
238 }
239
240 // Place elements vertically
241 double ypc = ((double)(d[i].y - oldy) / (double)oldheight);
242 d[i].y = int32_t(d[0].y + (ypc*d[0].h));
243
244 // Vertically resize elements
245 if(d[i].proc == jwin_edit_proc || d[i].proc == jwin_check_proc || d[i].proc == jwin_checkfont_proc)
246 {
247 d[i].h = int32_t((double)d[i].h*1.5);
248 }
249 else if(d[i].proc == jwin_droplist_proc || d[i].proc == d_joylist_proc)
250 {
251 d[i].y += int32_t((double)d[i].h*0.25);
252 d[i].h = int32_t((double)d[i].h*1.25);
253 }
254 else if(d[i].proc==d_bitmap_proc)
255 {
256 d[i].h *= 2;
257 }
258 else d[i].h = int32_t(d[i].h*RESIZE_AMT);
259
260 // Fix frames
261 if(d[i].proc == jwin_frame_proc)
262 {
263 d[i].x++;
264 d[i].y++;
265 d[i].w-=4;
266 d[i].h-=4;
267 }
268 }
269 }
270
271 for(int32_t i=1; d[i].proc!=NULL; i++)
272 {
273 if(d[i].proc==jwin_slider_proc)
274 continue;
275
276 // Bigger font
277 bool bigfontproc = (d[i].proc != d_midilist_proc && d[i].proc != jwin_droplist_proc && d[i].proc != jwin_abclist_proc && d[i].proc != jwin_list_proc && d[i].proc != d_joylist_proc);
278
279 if(!d[i].dp2 && bigfontproc)
280 {
281 d[i].dp2 = get_zc_font(font_lfont_l);
282 }
283 else if(!bigfontproc)
284 {
285 ((ListData *)d[i].dp)->font = &a4fonts[font_lfont_l];
286 }
287
288 // Make checkboxes work
289 if(d[i].proc == jwin_check_proc)
290 d[i].proc = jwin_checkfont_proc;
291 else if(d[i].proc == jwin_radio_proc)
292 d[i].proc = jwin_radiofont_proc;
293 }
294
295 jwin_center_dialog(d);
296 }
297
298 static char cfg_sect[] = "zeldadx"; //We need to rename this.
299 static char ctrl_sect[] = "Controls";
300 static char sfx_sect[] = "Volume";
301
302 int32_t d_dummy_proc(int32_t,DIALOG *,int32_t)
303 {
304 return D_O_K;
305 }
306
307 bool is_reserved_key(int c)
308 {
309 switch(c)
310 {
311 case KEY_ESC:
312 return true;
313 }
314 return false;
315 }
316 bool is_reserved_keycombo(int c, int modflag)
317 {
318 if(c==KEY_F4 && (modflag&KB_ALT_FLAG))
319 return true;
320 return false;
321 }
322 bool checkcheat(Cheat cheat)
323 {
324 if(cheatkeys[cheat][0] && zc_readkey(cheatkeys[cheat][0]))
325 return true; //Main key pressed
326 if(cheatkeys[cheat][1] && zc_readkey(cheatkeys[cheat][1]))
327 return true; //Alt key pressed
328 return false;
329 }
330 239 void load_default_cheatkeys()
331 {
332 239 memset(cheatkeys, 0, sizeof(cheatkeys));
333 239 cheatkeys[Cheat::Life][0] = KEY_H;
334 239 cheatkeys[Cheat::Life][1] = KEY_ASTERISK;
335 239 cheatkeys[Cheat::Magic][0] = KEY_M;
336 239 cheatkeys[Cheat::Magic][1] = KEY_SLASH_PAD;
337 239 cheatkeys[Cheat::Rupies][0] = KEY_R;
338 239 cheatkeys[Cheat::Bombs][0] = KEY_B;
339 239 cheatkeys[Cheat::Arrows][0] = KEY_A;
340 239 cheatkeys[Cheat::Clock][0] = KEY_I;
341 239 cheatkeys[Cheat::Walls][0] = KEY_F11;
342 239 cheatkeys[Cheat::Fast][0] = KEY_Q;
343 239 cheatkeys[Cheat::Light][0] = KEY_L;
344 239 cheatkeys[Cheat::IgnoreSideView][0] = KEY_V;
345 239 cheatkeys[Cheat::Kill][0] = KEY_K;
346 239 cheatkeys[Cheat::GoTo][0] = KEY_G;
347 239 cheatkeys[Cheat::TrigSecrets][0] = KEY_S;
348 239 cheatkeys[Cheat::ShowL0][0] = KEY_0;
349 239 cheatkeys[Cheat::ShowL1][0] = KEY_1;
350 239 cheatkeys[Cheat::ShowL2][0] = KEY_2;
351 239 cheatkeys[Cheat::ShowL3][0] = KEY_3;
352 239 cheatkeys[Cheat::ShowL4][0] = KEY_4;
353 239 cheatkeys[Cheat::ShowL5][0] = KEY_5;
354 239 cheatkeys[Cheat::ShowL6][0] = KEY_6;
355 239 cheatkeys[Cheat::ShowFFC][0] = KEY_7;
356 239 cheatkeys[Cheat::ShowSprites][0] = KEY_8;
357 239 cheatkeys[Cheat::ShowWalkability][0] = KEY_W;
358 239 cheatkeys[Cheat::ShowEffects][0] = KEY_E;
359 239 cheatkeys[Cheat::ShowOverhead][0] = KEY_O;
360 239 cheatkeys[Cheat::ShowPushblock][0] = KEY_P;
361 239 cheatkeys[Cheat::ShowHitbox][0] = KEY_C;
362 239 cheatkeys[Cheat::ShowFFCScripts][0] = KEY_F;
363 239 }
364
365 static bool loaded_game_configs;
366
367 239 void load_game_configs()
368 {
369 239 loaded_game_configs = true;
370 239 strcpy(moduledata.module_name,zc_get_config("ZCMODULE",qst_module_name,"modules/classic.zmod"));
371 239 joystick_index = zc_get_config(ctrl_sect,"joystick_index",0);
372 239 js_stick_1_x_stick = zc_get_config(ctrl_sect,"js_stick_1_x_stick",0);
373 239 js_stick_1_x_axis = zc_get_config(ctrl_sect,"js_stick_1_x_axis",0);
374 239 js_stick_1_x_offset = zc_get_config(ctrl_sect,"js_stick_1_x_offset",0) ? 128 : 0;
375 239 js_stick_1_y_stick = zc_get_config(ctrl_sect,"js_stick_1_y_stick",0);
376 239 js_stick_1_y_axis = zc_get_config(ctrl_sect,"js_stick_1_y_axis",1);
377 239 js_stick_1_y_offset = zc_get_config(ctrl_sect,"js_stick_1_y_offset",0) ? 128 : 0;
378 239 js_stick_2_x_stick = zc_get_config(ctrl_sect,"js_stick_2_x_stick",1);
379 239 js_stick_2_x_axis = zc_get_config(ctrl_sect,"js_stick_2_x_axis",0);
380 239 js_stick_2_x_offset = zc_get_config(ctrl_sect,"js_stick_2_x_offset",0) ? 128 : 0;
381 239 js_stick_2_y_stick = zc_get_config(ctrl_sect,"js_stick_2_y_stick",1);
382 239 js_stick_2_y_axis = zc_get_config(ctrl_sect,"js_stick_2_y_axis",1);
383 239 js_stick_2_y_offset = zc_get_config(ctrl_sect,"js_stick_2_y_offset",0) ? 128 : 0;
384 239 analog_movement = (zc_get_config(ctrl_sect,"analog_movement",1));
385
386 //cheat modifier keya
387 239 cheat_modifier_keys[0] = zc_get_config(ctrl_sect,"key_cheatmod_a1",KEY_ZC_LCONTROL);
388 239 cheat_modifier_keys[1] = zc_get_config(ctrl_sect,"key_cheatmod_a2",0);
389 239 cheat_modifier_keys[2] = zc_get_config(ctrl_sect,"key_cheatmod_b1",KEY_ZC_RCONTROL);
390 239 cheat_modifier_keys[3] = zc_get_config(ctrl_sect,"key_cheatmod_b2",0);
391
392 //cheat keys
393 239 load_default_cheatkeys();
394 char buf[256];
395
2/2
✓ Branch 0 taken 239 times.
✓ Branch 1 taken 8604 times.
8843 for(size_t q = 1; q < Cheat::Last; ++q)
396 {
397
1/2
✓ Branch 0 taken 8604 times.
✗ Branch 1 not taken.
8604 if(!bindable_cheat((Cheat)q)) continue;
398 8604 std::string cheatname = cheat_to_string((Cheat)q);
399
1/2
✓ Branch 0 taken 8604 times.
✗ Branch 1 not taken.
8604 util::lowerstr(cheatname);
400 8604 sprintf(buf, "key_cheat_%s_main", cheatname.c_str());
401
1/2
✓ Branch 0 taken 8604 times.
✗ Branch 1 not taken.
8604 cheatkeys[q][0] = zc_get_config(ctrl_sect,buf,cheatkeys[q][0]);
402 8604 sprintf(buf, "key_cheat_%s_alt", cheatname.c_str());
403
1/2
✓ Branch 0 taken 8604 times.
✗ Branch 1 not taken.
8604 cheatkeys[q][1] = zc_get_config(ctrl_sect,buf,cheatkeys[q][1]);
404 8604 }
405
406
1/2
✓ Branch 0 taken 239 times.
✗ Branch 1 not taken.
239 if((uint32_t)joystick_index >= MAX_JOYSTICKS)
407 joystick_index = 0;
408
409 239 Akey = zc_get_config(ctrl_sect,"key_a",KEY_Z);
410 239 Bkey = zc_get_config(ctrl_sect,"key_b",KEY_X);
411 239 Skey = zc_get_config(ctrl_sect,"key_s",KEY_ENTER);
412 239 Lkey = zc_get_config(ctrl_sect,"key_l",KEY_Q);
413 239 Rkey = zc_get_config(ctrl_sect,"key_r",KEY_W);
414 239 Pkey = zc_get_config(ctrl_sect,"key_p",KEY_SPACE);
415 239 Exkey1 = zc_get_config(ctrl_sect,"key_ex1",KEY_A);
416 239 Exkey2 = zc_get_config(ctrl_sect,"key_ex2",KEY_S);
417 239 Exkey3 = zc_get_config(ctrl_sect,"key_ex3",KEY_D);
418 239 Exkey4 = zc_get_config(ctrl_sect,"key_ex4",KEY_C);
419
420 239 DUkey = zc_get_config(ctrl_sect,"key_up", KEY_UP);
421 239 DDkey = zc_get_config(ctrl_sect,"key_down", KEY_DOWN);
422 239 DLkey = zc_get_config(ctrl_sect,"key_left", KEY_LEFT);
423 239 DRkey = zc_get_config(ctrl_sect,"key_right",KEY_RIGHT);
424
425 239 Abtn = zc_get_config(ctrl_sect,"btn_a",2);
426 239 Bbtn = zc_get_config(ctrl_sect,"btn_b",1);
427 239 Sbtn = zc_get_config(ctrl_sect,"btn_s",10);
428 239 Mbtn = zc_get_config(ctrl_sect,"btn_m",9);
429 239 Lbtn = zc_get_config(ctrl_sect,"btn_l",5);
430 239 Rbtn = zc_get_config(ctrl_sect,"btn_r",6);
431 239 Pbtn = zc_get_config(ctrl_sect,"btn_p",12);
432 239 Exbtn1 = zc_get_config(ctrl_sect,"btn_ex1",7);
433 239 Exbtn2 = zc_get_config(ctrl_sect,"btn_ex2",8);
434 239 Exbtn3 = zc_get_config(ctrl_sect,"btn_ex3",4);
435 239 Exbtn4 = zc_get_config(ctrl_sect,"btn_ex4",3);
436
437 239 DUbtn = zc_get_config(ctrl_sect,"btn_up",13);
438 239 DDbtn = zc_get_config(ctrl_sect,"btn_down",14);
439 239 DLbtn = zc_get_config(ctrl_sect,"btn_left",15);
440 239 DRbtn = zc_get_config(ctrl_sect,"btn_right",16);
441
442 239 epilepsyFlashReduction = zc_get_config(cfg_sect,"epilepsy_flash_reduction",0);
443
444 239 midi_volume = zc_get_config(sfx_sect,"midi",255);
445 239 sfx_volume = zc_get_config(sfx_sect,"sfx",255);
446 239 emusic_volume = zc_get_config(sfx_sect,"emusic",255);
447 239 pan_style = zc_get_config(sfx_sect,"pan",1);
448 239 volkeys = zc_get_config(sfx_sect,"volkeys",0)!=0;
449 239 zc_vsync = zc_get_config(cfg_sect,"vsync",0);
450 239 Throttlefps = zc_get_config(cfg_sect,"throttlefps",1)!=0;
451 239 Maxfps = zc_get_config(cfg_sect,"maxfps",0);
452 239 TransLayers = zc_get_config(cfg_sect,"translayers",1)!=0;
453 239 SnapshotFormat = zc_get_config(cfg_sect,"snapshot_format",3);
454 239 SnapshotScale = zc_get_config(cfg_sect,"snapshot_scale",2);
455 239 NameEntryMode = zc_get_config(cfg_sect,"name_entry_mode",0);
456 #ifdef __EMSCRIPTEN__
457 if (em_is_mobile()) NameEntryMode = 2;
458 #endif
459 239 ShowFPS = zc_get_config(cfg_sect,"showfps",0)!=0;
460 239 ShowGameTime = zc_get_config(cfg_sect,"showtime",0);
461 239 NESquit = zc_get_config(cfg_sect,"fastquit",0)!=0;
462 239 ClickToFreeze = zc_get_config(cfg_sect,"clicktofreeze",1)!=0;
463 239 abc_patternmatch = zc_get_config(cfg_sect, "lister_pattern_matching", 1);
464 239 pause_in_background = zc_get_config(cfg_sect, "pause_in_background", 0);
465
466 239 window_width = resx = zc_get_config(cfg_sect,"window_width",-1);
467 239 window_height = resy = zc_get_config(cfg_sect,"window_height",-1);
468 239 SaveDragResize = zc_get_config(cfg_sect,"save_drag_resize",0)!=0;
469 239 DragAspect = zc_get_config(cfg_sect,"drag_aspect",0)!=0;
470 239 SaveWinPos = zc_get_config(cfg_sect,"save_window_position",0)!=0;
471 239 scaleForceInteger = zc_get_config("zeldadx","scaling_force_integer",1)!=0;
472 239 stretchGame = zc_get_config("zeldadx","stretch_game_area",0)!=0;
473
474 239 loadlast = zc_get_config(cfg_sect,"load_last",0);
475
476 239 fullscreen = zc_get_config(cfg_sect,"fullscreen",0);
477
478 239 info_opacity = zc_get_config("zc","debug_info_opacity",255);
479 #ifdef _WIN32
480 console_enabled = (byte) zc_get_config("CONSOLE", "enabled", 0);
481 //use_win7_keyboard_fix = (byte) zc_get_config(cfg_sect,"use_win7_key_fix",0);
482 use_win32_proc = (byte) zc_get_config(cfg_sect,"zc_win_proc_fix",0); //buggy
483
484 // This one's for Aero
485 use_dwm_flush = (byte) zc_get_config("zeldadx","use_dwm_flush",0);
486
487 monochrome_console = (byte) zc_get_config("CONSOLE","monochrome_debuggers",0);
488 #else //UNIX
489 239 console_enabled = (byte) zc_get_config("CONSOLE", "enabled", 0);
490 239 monochrome_console = (byte) zc_get_config("CONSOLE","monochrome_debuggers",0);
491 #endif
492 239 clearConsoleOnLoad = zc_get_config("CONSOLE","clear_console_on_load",1)!=0;
493 239 clearConsoleOnReload = zc_get_config("CONSOLE","clear_console_on_reload",0)!=0;
494
495 239 strcpy(qstdir,zc_get_config(cfg_sect,"quest_dir","quests"));
496 239 strcpy(qstpath,qstdir); //qstpath is the local (for this run of ZC) quest path, qstdir is the universal quest dir.
497 239 ss_enable = zc_get_config(cfg_sect,"ss_enable",1) ? 1 : 0;
498 239 ss_after = vbound(zc_get_config(cfg_sect,"ss_after",14), 0, 14);
499 239 ss_speed = vbound(zc_get_config(cfg_sect,"ss_speed",2), 0, 6);
500 239 ss_density = vbound(zc_get_config(cfg_sect,"ss_density",3), 0, 6);
501 239 heart_beep = zc_get_config(cfg_sect,"heart_beep",0)!=0;
502 //gui_colorset = zc_get_config(cfg_sect,"gui_colorset",0);
503 239 sfxdat = zc_get_config(cfg_sect,"use_sfx_dat",1);
504 239 fullscreen = zc_get_config(cfg_sect,"fullscreen",0);
505 239 use_save_indicator = zc_get_config(cfg_sect,"save_indicator",0);
506 239 zc_192b163_warp_compatibility = zc_get_config(cfg_sect,"zc_192b163_warp_compatibility",0);
507 239 SkipTitle = zc_get_config(cfg_sect,"skip_title",0);
508 239 }
509
510 void save_control_configs(bool kb)
511 {
512 if(kb)
513 {
514 zc_set_config(ctrl_sect,"key_cheatmod_a1",cheat_modifier_keys[0]);
515 zc_set_config(ctrl_sect,"key_cheatmod_a2",cheat_modifier_keys[1]);
516 zc_set_config(ctrl_sect,"key_cheatmod_b1",cheat_modifier_keys[2]);
517 zc_set_config(ctrl_sect,"key_cheatmod_b2",cheat_modifier_keys[3]);
518
519 if (!replay_is_replaying())
520 {
521 zc_set_config(ctrl_sect,"key_a",Akey);
522 zc_set_config(ctrl_sect,"key_b",Bkey);
523 zc_set_config(ctrl_sect,"key_s",Skey);
524 zc_set_config(ctrl_sect,"key_l",Lkey);
525 zc_set_config(ctrl_sect,"key_r",Rkey);
526 zc_set_config(ctrl_sect,"key_p",Pkey);
527 zc_set_config(ctrl_sect,"key_ex1",Exkey1);
528 zc_set_config(ctrl_sect,"key_ex2",Exkey2);
529 zc_set_config(ctrl_sect,"key_ex3",Exkey3);
530 zc_set_config(ctrl_sect,"key_ex4",Exkey4);
531 zc_set_config(ctrl_sect,"key_up", DUkey);
532 zc_set_config(ctrl_sect,"key_down", DDkey);
533 zc_set_config(ctrl_sect,"key_left", DLkey);
534 zc_set_config(ctrl_sect,"key_right",DRkey);
535 }
536 }
537 else
538 {
539 zc_set_config(ctrl_sect,"joystick_index",joystick_index);
540 zc_set_config(ctrl_sect,"js_stick_1_x_stick",js_stick_1_x_stick);
541 zc_set_config(ctrl_sect,"js_stick_1_x_axis",js_stick_1_x_axis);
542 zc_set_config(ctrl_sect,"js_stick_1_x_offset",js_stick_1_x_offset ? 1 : 0);
543 zc_set_config(ctrl_sect,"js_stick_1_y_stick",js_stick_1_y_stick);
544 zc_set_config(ctrl_sect,"js_stick_1_y_axis",js_stick_1_y_axis);
545 zc_set_config(ctrl_sect,"js_stick_1_y_offset",js_stick_1_y_offset ? 1 : 0);
546 zc_set_config(ctrl_sect,"js_stick_2_x_stick",js_stick_2_x_stick);
547 zc_set_config(ctrl_sect,"js_stick_2_x_axis",js_stick_2_x_axis);
548 zc_set_config(ctrl_sect,"js_stick_2_x_offset",js_stick_2_x_offset ? 1 : 0);
549 zc_set_config(ctrl_sect,"js_stick_2_y_stick",js_stick_2_y_stick);
550 zc_set_config(ctrl_sect,"js_stick_2_y_axis",js_stick_2_y_axis);
551 zc_set_config(ctrl_sect,"js_stick_2_y_offset",js_stick_2_y_offset ? 1 : 0);
552 zc_set_config(ctrl_sect,"analog_movement",analog_movement);
553
554 zc_set_config(ctrl_sect,"btn_a",Abtn);
555 zc_set_config(ctrl_sect,"btn_b",Bbtn);
556 zc_set_config(ctrl_sect,"btn_s",Sbtn);
557 zc_set_config(ctrl_sect,"btn_m",Mbtn);
558 zc_set_config(ctrl_sect,"btn_l",Lbtn);
559 zc_set_config(ctrl_sect,"btn_r",Rbtn);
560 zc_set_config(ctrl_sect,"btn_p",Pbtn);
561 zc_set_config(ctrl_sect,"btn_ex1",Exbtn1);
562 zc_set_config(ctrl_sect,"btn_ex2",Exbtn2);
563 zc_set_config(ctrl_sect,"btn_ex3",Exbtn3);
564 zc_set_config(ctrl_sect,"btn_ex4",Exbtn4);
565
566 zc_set_config(ctrl_sect,"btn_up",DUbtn);
567 zc_set_config(ctrl_sect,"btn_down",DDbtn);
568 zc_set_config(ctrl_sect,"btn_left",DLbtn);
569 zc_set_config(ctrl_sect,"btn_right",DRbtn);
570 }
571 }
572
573 void save_cheatkeys()
574 {
575 char buf[256];
576 for(size_t q = 1; q < Cheat::Last; ++q)
577 {
578 if(!bindable_cheat((Cheat)q)) continue;
579 std::string cheatname = cheat_to_string((Cheat)q);
580 util::lowerstr(cheatname);
581 sprintf(buf, "key_cheat_%s_main", cheatname.c_str());
582 zc_set_config(ctrl_sect,buf,cheatkeys[q][0]);
583 sprintf(buf, "key_cheat_%s_alt", cheatname.c_str());
584 if(cheatkeys[q][1])
585 zc_set_config(ctrl_sect,buf,cheatkeys[q][1]);
586 else zc_set_config(ctrl_sect,buf,(char*)nullptr);
587 }
588 }
589
590 239 void save_game_configs()
591 {
592
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 239 times.
239 if (!loaded_game_configs) return;
593
594 239 packfile_password("");
595
596 239 zc_set_config("ZCMODULE",qst_module_name,moduledata.module_name);
597
598
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 239 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
239 if (all_get_display() && !all_get_fullscreen_flag()&& SaveWinPos)
599 {
600 int o_window_x, o_window_y;
601 al_get_window_position(all_get_display(), &o_window_x, &o_window_y);
602 zc_set_config(cfg_sect,"window_x",o_window_x);
603 zc_set_config(cfg_sect,"window_y",o_window_y);
604 }
605
606
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 239 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
239 if (all_get_display() && !all_get_fullscreen_flag() && SaveDragResize)
607 {
608 window_width = al_get_display_width(all_get_display());
609 window_height = al_get_display_height(all_get_display());
610 zc_set_config(cfg_sect,"window_width",window_width);
611 zc_set_config(cfg_sect,"window_height",window_height);
612 }
613
614 239 zc_set_config(cfg_sect,"load_last",loadlast);
615 239 zc_set_config(cfg_sect,"use_sfx_dat",sfxdat);
616
617 239 flush_config_file();
618 #ifdef __EMSCRIPTEN__
619 em_sync_fs();
620 #endif
621 239 }
622
623 //----------------------------------------------------------------
624
625 // Timers
626
627 43463 void fps_callback()
628 {
629 43463 lastfps=framecnt;
630 43463 framecnt=0;
631 43463 }
632
633 END_OF_FUNCTION(fps_callback)
634
635 239 int32_t Z_init_timers()
636 {
637 static bool didit = false;
638 const static char *err_str = "Couldn't allocate timer";
639 239 err_str = err_str; //Unused variable warning
640
641
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 239 times.
239 if(didit)
642 return 1;
643
644 239 didit = true;
645
646 LOCK_VARIABLE(lastfps);
647 LOCK_VARIABLE(framecnt);
648 LOCK_FUNCTION(fps_callback);
649
650
1/2
✓ Branch 0 taken 239 times.
✗ Branch 1 not taken.
239 if(install_int_ex(fps_callback,SECS_TO_TIMER(1)))
651 return 0;
652
653 239 return 1;
654 239 }
655
656 239 void Z_remove_timers()
657 {
658 239 remove_int(fps_callback);
659 239 }
660
661 //----------------------------------------------------------------
662
663 void go()
664 {
665 blit(screen,tmp_scr,scrx,scry,0,0,screen->w,screen->h);
666 }
667
668 void comeback()
669 {
670 blit(tmp_scr,screen,0,0,scrx,scry,screen->w,screen->h);
671 }
672
673 void dump_pal(BITMAP *dest)
674 {
675 for(int32_t i=0; i<256; i++)
676 rectfill(dest,(i&63)<<2,(i&0xFC0)>>4,((i&63)<<2)+3,((i&0xFC0)>>4)+3,i);
677 }
678
679 //----------------------------------------------------------------
680
681 int game_mouse_index = ZCM_BLANK;
682 static bool system_mouse = false;
683 110 bool sys_mouse()
684 {
685 110 system_mouse = true;
686 110 return MouseSprite::set(ZCM_NORMAL);
687 }
688 1467 bool game_mouse()
689 {
690 1467 system_mouse = false;
691 1467 return MouseSprite::set(game_mouse_index);
692 }
693 void custom_mouse(BITMAP* bmp, int fx, int fy, bool sys_recolor, bool user_scale)
694 {
695 if(!bmp)
696 return;
697 float scale = vbound(zc_get_config("zeldadx","cursor_scale_large",1.5),1.0,5.0);
698 int scaledw = bmp->w*scale, scaledh = bmp->h*scale;
699 if(bmp->w == scaledw && bmp->h == scaledh)
700 user_scale = false;
701 if(user_scale || sys_recolor)
702 {
703 if(!user_scale) scale = 1;
704 BITMAP* tmpbmp = create_bitmap_ex(8,bmp->w*scale,bmp->h*scale);
705 if(user_scale)
706 stretch_blit(bmp, tmpbmp, 0, 0, bmp->w, bmp->h, 0, 0, tmpbmp->w, tmpbmp->h);
707 else
708 blit(bmp, tmpbmp, 0, 0, 0, 0, bmp->w, bmp->h);
709 if(sys_recolor)
710 recolor_mouse(tmpbmp);
711 MouseSprite::assign(ZCM_CUSTOM, tmpbmp, fx*scale, fy*scale);
712 destroy_bitmap(tmpbmp);
713 }
714 else
715 {
716 MouseSprite::assign(ZCM_CUSTOM, bmp, fx, fy);
717 }
718 }
719
720 //Handles converting the mouse sprite from the .dat file
721 void recolor_mouse(BITMAP* bmp)
722 {
723 for(int32_t x = 0; x < bmp->w; ++x)
724 {
725 for(int32_t y = 0; y < bmp->h; ++y)
726 {
727 int32_t color = getpixel(bmp, x, y);
728 switch(color)
729 {
730 case dvc(1):
731 color = jwin_pal[jcCURSORMISC];
732 break;
733 case dvc(2):
734 color = jwin_pal[jcCURSOROUTLINE];
735 break;
736 case dvc(3):
737 color = jwin_pal[jcCURSORLIGHT];
738 break;
739 case dvc(5):
740 color = jwin_pal[jcCURSORDARK];
741 break;
742 default:
743 continue;
744 }
745 putpixel(bmp, x, y, color);
746 }
747 }
748 }
749 void load_mouse()
750 {
751 PALETTE pal;
752 BITMAP* cursor_bitmap = load_bitmap("assets/cursor.bmp", pal);
753 if (!cursor_bitmap)
754 Z_error_fatal("Missing required file %s\n", "assets/cursor.bmp");
755
756 enter_sys_pal();
757 MouseSprite::set(-1);
758 float scale = vbound(zc_get_config("zeldadx","cursor_scale_large",1.5),1.0,5.0);
759 int32_t sz = 16*scale;
760 for(int32_t j = 0; j < 1; ++j)
761 {
762 BITMAP* tmpbmp = create_bitmap_ex(8,16,16);
763 if(zcmouse[j])
764 destroy_bitmap(zcmouse[j]);
765 zcmouse[j] = create_bitmap_ex(8,sz,sz);
766 clear_bitmap(zcmouse[j]);
767 clear_bitmap(tmpbmp);
768 blit(cursor_bitmap,tmpbmp,1,j*17+1,0,0,16,16);
769 recolor_mouse(tmpbmp);
770 if(sz!=16)
771 stretch_blit(tmpbmp, zcmouse[j], 0, 0, 16, 16, 0, 0, sz, sz);
772 else
773 blit(tmpbmp, zcmouse[j], 0, 0, 0, 0, 16, 16);
774 destroy_bitmap(tmpbmp);
775 }
776 if(!hw_palette) hw_palette = &RAMpal;
777 zc_set_palette(*hw_palette);
778
779 BITMAP* blankmouse = create_bitmap_ex(8,16,16);
780 clear_bitmap(blankmouse);
781
782 MouseSprite::assign(ZCM_NORMAL, zcmouse[0], 1*scale, 1*scale);
783 MouseSprite::assign(ZCM_BLANK, blankmouse);
784 //Don't assign ZCM_CUSTOM. That'll be handled by scripts.
785
786 //Reload the mouse
787 if(system_mouse)
788 sys_mouse();
789 else game_mouse();
790
791 destroy_bitmap(blankmouse);
792 destroy_bitmap(cursor_bitmap);
793 exit_sys_pal();
794 }
795
796 // sets the video mode and initializes the palette and mouse sprite
797 239 bool game_vid_mode(int32_t mode,int32_t wait)
798 {
799
1/2
✓ Branch 0 taken 239 times.
✗ Branch 1 not taken.
239 if (is_headless())
800 239 return true;
801
802 extern int zq_screen_w, zq_screen_h;
803 if(set_gfx_mode(mode,resx,resy,zq_screen_w,zq_screen_h)!=0)
804 {
805 return false;
806 }
807
808 scrx = (resx-320)>>1;
809 scry = (resy-240)>>1;
810 for(int32_t q = 0; q < NUM_ZCMOUSE; ++q)
811 zcmouse[q] = NULL;
812 load_mouse();
813
814 for(int32_t i=240; i<256; i++)
815 RAMpal[i]=pal_gui[i];
816
817 zc_set_palette(RAMpal);
818 clear_to_color(screen,BLACK);
819
820 rest(wait);
821 return true;
822 239 }
823
824 247 void null_quest()
825 {
826 char qstdat_string[2048];
827 247 strcpy(qstdat_string, "modules/classic/default.qst");
828
829 #ifdef __EMSCRIPTEN__
830 // The quest template data file is not included because it's really big and isn't really needed
831 // for the player, except to initialize some graphics. Those same graphics exist in this quest file,
832 // which is much smaller.
833 strcpy(qstdat_string, "modules/classic/title_gfx.dat");
834 #endif
835
836 247 byte skip_flags[4] = { 0 };
837
838 247 loadquest(qstdat_string,&QHeader,&QMisc,tunes+ZC_MIDI_COUNT,false,skip_flags,0,false);
839 247 }
840
841 247 void init_NES_mode()
842 {
843 247 null_quest();
844 247 }
845
846 //----------------------------------------------------------------
847
848 qword trianglelines[16]=
849 {
850 0x0000000000000000ULL,
851 0xFD00000000000000ULL,
852 0xFDFD000000000000ULL,
853 0xFDFDFD0000000000ULL,
854 0xFDFDFDFD00000000ULL,
855 0xFDFDFDFDFD000000ULL,
856 0xFDFDFDFDFDFD0000ULL,
857 0xFDFDFDFDFDFDFD00ULL,
858 0xFDFDFDFDFDFDFDFDULL,
859 0x00FDFDFDFDFDFDFDULL,
860 0x0000FDFDFDFDFDFDULL,
861 0x000000FDFDFDFDFDULL,
862 0x00000000FDFDFDFDULL,
863 0x0000000000FDFDFDULL,
864 0x000000000000FDFDULL,
865 0x00000000000000FDULL,
866 };
867
868 word screen_triangles[28][32];
869
870 // the ULL suffixes are to prevent this warning:
871 // warning: integer constant is too large for "int32_t" type
872
873 qword triangles[4][16][8]= //[direction][value][line]
874 {
875 {
876 {
877 0x0000000000000000ULL,
878 0x0000000000000000ULL,
879 0x0000000000000000ULL,
880 0x0000000000000000ULL,
881 0x0000000000000000ULL,
882 0x0000000000000000ULL,
883 0x0000000000000000ULL,
884 0x0000000000000000ULL
885 },
886 {
887 0xFD00000000000000ULL,
888 0x0000000000000000ULL,
889 0x0000000000000000ULL,
890 0x0000000000000000ULL,
891 0x0000000000000000ULL,
892 0x0000000000000000ULL,
893 0x0000000000000000ULL,
894 0x0000000000000000ULL
895 },
896 {
897 0xFDFD000000000000ULL,
898 0xFD00000000000000ULL,
899 0x0000000000000000ULL,
900 0x0000000000000000ULL,
901 0x0000000000000000ULL,
902 0x0000000000000000ULL,
903 0x0000000000000000ULL,
904 0x0000000000000000ULL
905 },
906 {
907 0xFDFDFD0000000000ULL,
908 0xFDFD000000000000ULL,
909 0xFD00000000000000ULL,
910 0x0000000000000000ULL,
911 0x0000000000000000ULL,
912 0x0000000000000000ULL,
913 0x0000000000000000ULL,
914 0x0000000000000000ULL
915 },
916 {
917 0xFDFDFDFD00000000ULL,
918 0xFDFDFD0000000000ULL,
919 0xFDFD000000000000ULL,
920 0xFD00000000000000ULL,
921 0x0000000000000000ULL,
922 0x0000000000000000ULL,
923 0x0000000000000000ULL,
924 0x0000000000000000ULL
925 },
926 {
927 0xFDFDFDFDFD000000ULL,
928 0xFDFDFDFD00000000ULL,
929 0xFDFDFD0000000000ULL,
930 0xFDFD000000000000ULL,
931 0xFD00000000000000ULL,
932 0x0000000000000000ULL,
933 0x0000000000000000ULL,
934 0x0000000000000000ULL
935 },
936 {
937 0xFDFDFDFDFDFD0000ULL,
938 0xFDFDFDFDFD000000ULL,
939 0xFDFDFDFD00000000ULL,
940 0xFDFDFD0000000000ULL,
941 0xFDFD000000000000ULL,
942 0xFD00000000000000ULL,
943 0x0000000000000000ULL,
944 0x0000000000000000ULL
945 },
946 {
947 0xFDFDFDFDFDFDFD00ULL,
948 0xFDFDFDFDFDFD0000ULL,
949 0xFDFDFDFDFD000000ULL,
950 0xFDFDFDFD00000000ULL,
951 0xFDFDFD0000000000ULL,
952 0xFDFD000000000000ULL,
953 0xFD00000000000000ULL,
954 0x0000000000000000ULL
955 },
956 {
957 0xFDFDFDFDFDFDFDFDULL,
958 0xFDFDFDFDFDFDFD00ULL,
959 0xFDFDFDFDFDFD0000ULL,
960 0xFDFDFDFDFD000000ULL,
961 0xFDFDFDFD00000000ULL,
962 0xFDFDFD0000000000ULL,
963 0xFDFD000000000000ULL,
964 0xFD00000000000000ULL
965 },
966 {
967 0xFDFDFDFDFDFDFDFDULL,
968 0xFDFDFDFDFDFDFDFDULL,
969 0xFDFDFDFDFDFDFD00ULL,
970 0xFDFDFDFDFDFD0000ULL,
971 0xFDFDFDFDFD000000ULL,
972 0xFDFDFDFD00000000ULL,
973 0xFDFDFD0000000000ULL,
974 0xFDFD000000000000ULL
975 },
976 {
977 0xFDFDFDFDFDFDFDFDULL,
978 0xFDFDFDFDFDFDFDFDULL,
979 0xFDFDFDFDFDFDFDFDULL,
980 0xFDFDFDFDFDFDFD00ULL,
981 0xFDFDFDFDFDFD0000ULL,
982 0xFDFDFDFDFD000000ULL,
983 0xFDFDFDFD00000000ULL,
984 0xFDFDFD0000000000ULL
985 },
986 {
987 0xFDFDFDFDFDFDFDFDULL,
988 0xFDFDFDFDFDFDFDFDULL,
989 0xFDFDFDFDFDFDFDFDULL,
990 0xFDFDFDFDFDFDFDFDULL,
991 0xFDFDFDFDFDFDFD00ULL,
992 0xFDFDFDFDFDFD0000ULL,
993 0xFDFDFDFDFD000000ULL,
994 0xFDFDFDFD00000000ULL
995 },
996 {
997 0xFDFDFDFDFDFDFDFDULL,
998 0xFDFDFDFDFDFDFDFDULL,
999 0xFDFDFDFDFDFDFDFDULL,
1000 0xFDFDFDFDFDFDFDFDULL,
1001 0xFDFDFDFDFDFDFDFDULL,
1002 0xFDFDFDFDFDFDFD00ULL,
1003 0xFDFDFDFDFDFD0000ULL,
1004 0xFDFDFDFDFD000000ULL
1005 },
1006 {
1007 0xFDFDFDFDFDFDFDFDULL,
1008 0xFDFDFDFDFDFDFDFDULL,
1009 0xFDFDFDFDFDFDFDFDULL,
1010 0xFDFDFDFDFDFDFDFDULL,
1011 0xFDFDFDFDFDFDFDFDULL,
1012 0xFDFDFDFDFDFDFDFDULL,
1013 0xFDFDFDFDFDFDFD00ULL,
1014 0xFDFDFDFDFDFD0000ULL
1015 },
1016 {
1017 0xFDFDFDFDFDFDFDFDULL,
1018 0xFDFDFDFDFDFDFDFDULL,
1019 0xFDFDFDFDFDFDFDFDULL,
1020 0xFDFDFDFDFDFDFDFDULL,
1021 0xFDFDFDFDFDFDFDFDULL,
1022 0xFDFDFDFDFDFDFDFDULL,
1023 0xFDFDFDFDFDFDFDFDULL,
1024 0xFDFDFDFDFDFDFD00ULL
1025 },
1026 {
1027 0xFDFDFDFDFDFDFDFDULL,
1028 0xFDFDFDFDFDFDFDFDULL,
1029 0xFDFDFDFDFDFDFDFDULL,
1030 0xFDFDFDFDFDFDFDFDULL,
1031 0xFDFDFDFDFDFDFDFDULL,
1032 0xFDFDFDFDFDFDFDFDULL,
1033 0xFDFDFDFDFDFDFDFDULL,
1034 0xFDFDFDFDFDFDFDFDULL
1035 }
1036 },
1037 {
1038 {
1039 0x0000000000000000ULL,
1040 0x0000000000000000ULL,
1041 0x0000000000000000ULL,
1042 0x0000000000000000ULL,
1043 0x0000000000000000ULL,
1044 0x0000000000000000ULL,
1045 0x0000000000000000ULL,
1046 0x0000000000000000ULL
1047 },
1048 {
1049 0x00000000000000FDULL,
1050 0x0000000000000000ULL,
1051 0x0000000000000000ULL,
1052 0x0000000000000000ULL,
1053 0x0000000000000000ULL,
1054 0x0000000000000000ULL,
1055 0x0000000000000000ULL,
1056 0x0000000000000000ULL
1057 },
1058 {
1059 0x000000000000FDFDULL,
1060 0x00000000000000FDULL,
1061 0x0000000000000000ULL,
1062 0x0000000000000000ULL,
1063 0x0000000000000000ULL,
1064 0x0000000000000000ULL,
1065 0x0000000000000000ULL,
1066 0x0000000000000000ULL
1067 },
1068 {
1069 0x0000000000FDFDFDULL,
1070 0x000000000000FDFDULL,
1071 0x00000000000000FDULL,
1072 0x0000000000000000ULL,
1073 0x0000000000000000ULL,
1074 0x0000000000000000ULL,
1075 0x0000000000000000ULL,
1076 0x0000000000000000ULL
1077 },
1078 {
1079 0x00000000FDFDFDFDULL,
1080 0x0000000000FDFDFDULL,
1081 0x000000000000FDFDULL,
1082 0x00000000000000FDULL,
1083 0x0000000000000000ULL,
1084 0x0000000000000000ULL,
1085 0x0000000000000000ULL,
1086 0x0000000000000000ULL
1087 },
1088 {
1089 0x000000FDFDFDFDFDULL,
1090 0x00000000FDFDFDFDULL,
1091 0x0000000000FDFDFDULL,
1092 0x000000000000FDFDULL,
1093 0x00000000000000FDULL,
1094 0x0000000000000000ULL,
1095 0x0000000000000000ULL,
1096 0x0000000000000000ULL
1097 },
1098 {
1099 0x0000FDFDFDFDFDFDULL,
1100 0x000000FDFDFDFDFDULL,
1101 0x00000000FDFDFDFDULL,
1102 0x0000000000FDFDFDULL,
1103 0x000000000000FDFDULL,
1104 0x00000000000000FDULL,
1105 0x0000000000000000ULL,
1106 0x0000000000000000ULL
1107 },
1108 {
1109 0x00FDFDFDFDFDFDFDULL,
1110 0x0000FDFDFDFDFDFDULL,
1111 0x000000FDFDFDFDFDULL,
1112 0x00000000FDFDFDFDULL,
1113 0x0000000000FDFDFDULL,
1114 0x000000000000FDFDULL,
1115 0x00000000000000FDULL,
1116 0x0000000000000000ULL
1117 },
1118 {
1119 0xFDFDFDFDFDFDFDFDULL,
1120 0x00FDFDFDFDFDFDFDULL,
1121 0x0000FDFDFDFDFDFDULL,
1122 0x000000FDFDFDFDFDULL,
1123 0x00000000FDFDFDFDULL,
1124 0x0000000000FDFDFDULL,
1125 0x000000000000FDFDULL,
1126 0x00000000000000FDULL
1127 },
1128 {
1129 0xFDFDFDFDFDFDFDFDULL,
1130 0xFDFDFDFDFDFDFDFDULL,
1131 0x00FDFDFDFDFDFDFDULL,
1132 0x0000FDFDFDFDFDFDULL,
1133 0x000000FDFDFDFDFDULL,
1134 0x00000000FDFDFDFDULL,
1135 0x0000000000FDFDFDULL,
1136 0x000000000000FDFDULL
1137 },
1138 {
1139 0xFDFDFDFDFDFDFDFDULL,
1140 0xFDFDFDFDFDFDFDFDULL,
1141 0xFDFDFDFDFDFDFDFDULL,
1142 0x00FDFDFDFDFDFDFDULL,
1143 0x0000FDFDFDFDFDFDULL,
1144 0x000000FDFDFDFDFDULL,
1145 0x00000000FDFDFDFDULL,
1146 0x0000000000FDFDFDULL
1147 },
1148 {
1149 0xFDFDFDFDFDFDFDFDULL,
1150 0xFDFDFDFDFDFDFDFDULL,
1151 0xFDFDFDFDFDFDFDFDULL,
1152 0xFDFDFDFDFDFDFDFDULL,
1153 0x00FDFDFDFDFDFDFDULL,
1154 0x0000FDFDFDFDFDFDULL,
1155 0x000000FDFDFDFDFDULL,
1156 0x00000000FDFDFDFDULL
1157 },
1158 {
1159 0xFDFDFDFDFDFDFDFDULL,
1160 0xFDFDFDFDFDFDFDFDULL,
1161 0xFDFDFDFDFDFDFDFDULL,
1162 0xFDFDFDFDFDFDFDFDULL,
1163 0xFDFDFDFDFDFDFDFDULL,
1164 0x00FDFDFDFDFDFDFDULL,
1165 0x0000FDFDFDFDFDFDULL,
1166 0x000000FDFDFDFDFDULL
1167 },
1168 {
1169 0xFDFDFDFDFDFDFDFDULL,
1170 0xFDFDFDFDFDFDFDFDULL,
1171 0xFDFDFDFDFDFDFDFDULL,
1172 0xFDFDFDFDFDFDFDFDULL,
1173 0xFDFDFDFDFDFDFDFDULL,
1174 0xFDFDFDFDFDFDFDFDULL,
1175 0x00FDFDFDFDFDFDFDULL,
1176 0x0000FDFDFDFDFDFDULL
1177 },
1178 {
1179 0xFDFDFDFDFDFDFDFDULL,
1180 0xFDFDFDFDFDFDFDFDULL,
1181 0xFDFDFDFDFDFDFDFDULL,
1182 0xFDFDFDFDFDFDFDFDULL,
1183 0xFDFDFDFDFDFDFDFDULL,
1184 0xFDFDFDFDFDFDFDFDULL,
1185 0xFDFDFDFDFDFDFDFDULL,
1186 0x00FDFDFDFDFDFDFDULL
1187 },
1188 {
1189 0xFDFDFDFDFDFDFDFDULL,
1190 0xFDFDFDFDFDFDFDFDULL,
1191 0xFDFDFDFDFDFDFDFDULL,
1192 0xFDFDFDFDFDFDFDFDULL,
1193 0xFDFDFDFDFDFDFDFDULL,
1194 0xFDFDFDFDFDFDFDFDULL,
1195 0xFDFDFDFDFDFDFDFDULL,
1196 0xFDFDFDFDFDFDFDFDULL
1197 }
1198 },
1199 {
1200 {
1201 0x0000000000000000ULL,
1202 0x0000000000000000ULL,
1203 0x0000000000000000ULL,
1204 0x0000000000000000ULL,
1205 0x0000000000000000ULL,
1206 0x0000000000000000ULL,
1207 0x0000000000000000ULL,
1208 0x0000000000000000ULL
1209 },
1210 {
1211 0x0000000000000000ULL,
1212 0x0000000000000000ULL,
1213 0x0000000000000000ULL,
1214 0x0000000000000000ULL,
1215 0x0000000000000000ULL,
1216 0x0000000000000000ULL,
1217 0x0000000000000000ULL,
1218 0xFD00000000000000ULL
1219 },
1220 {
1221 0x0000000000000000ULL,
1222 0x0000000000000000ULL,
1223 0x0000000000000000ULL,
1224 0x0000000000000000ULL,
1225 0x0000000000000000ULL,
1226 0x0000000000000000ULL,
1227 0xFD00000000000000ULL,
1228 0xFDFD000000000000ULL
1229 },
1230 {
1231 0x0000000000000000ULL,
1232 0x0000000000000000ULL,
1233 0x0000000000000000ULL,
1234 0x0000000000000000ULL,
1235 0x0000000000000000ULL,
1236 0xFD00000000000000ULL,
1237 0xFDFD000000000000ULL,
1238 0xFDFDFD0000000000ULL
1239 },
1240 {
1241 0x0000000000000000ULL,
1242 0x0000000000000000ULL,
1243 0x0000000000000000ULL,
1244 0x0000000000000000ULL,
1245 0xFD00000000000000ULL,
1246 0xFDFD000000000000ULL,
1247 0xFDFDFD0000000000ULL,
1248 0xFDFDFDFD00000000ULL
1249 },
1250 {
1251 0x0000000000000000ULL,
1252 0x0000000000000000ULL,
1253 0x0000000000000000ULL,
1254 0xFD00000000000000ULL,
1255 0xFDFD000000000000ULL,
1256 0xFDFDFD0000000000ULL,
1257 0xFDFDFDFD00000000ULL,
1258 0xFDFDFDFDFD000000ULL
1259 },
1260 {
1261 0x0000000000000000ULL,
1262 0x0000000000000000ULL,
1263 0xFD00000000000000ULL,
1264 0xFDFD000000000000ULL,
1265 0xFDFDFD0000000000ULL,
1266 0xFDFDFDFD00000000ULL,
1267 0xFDFDFDFDFD000000ULL,
1268 0xFDFDFDFDFDFD0000ULL
1269 },
1270 {
1271 0x0000000000000000ULL,
1272 0xFD00000000000000ULL,
1273 0xFDFD000000000000ULL,
1274 0xFDFDFD0000000000ULL,
1275 0xFDFDFDFD00000000ULL,
1276 0xFDFDFDFDFD000000ULL,
1277 0xFDFDFDFDFDFD0000ULL,
1278 0xFDFDFDFDFDFDFD00ULL
1279 },
1280 {
1281 0xFD00000000000000ULL,
1282 0xFDFD000000000000ULL,
1283 0xFDFDFD0000000000ULL,
1284 0xFDFDFDFD00000000ULL,
1285 0xFDFDFDFDFD000000ULL,
1286 0xFDFDFDFDFDFD0000ULL,
1287 0xFDFDFDFDFDFDFD00ULL,
1288 0xFDFDFDFDFDFDFDFDULL
1289 },
1290 {
1291 0xFDFD000000000000ULL,
1292 0xFDFDFD0000000000ULL,
1293 0xFDFDFDFD00000000ULL,
1294 0xFDFDFDFDFD000000ULL,
1295 0xFDFDFDFDFDFD0000ULL,
1296 0xFDFDFDFDFDFDFD00ULL,
1297 0xFDFDFDFDFDFDFDFDULL,
1298 0xFDFDFDFDFDFDFDFDULL
1299 },
1300 {
1301 0xFDFDFD0000000000ULL,
1302 0xFDFDFDFD00000000ULL,
1303 0xFDFDFDFDFD000000ULL,
1304 0xFDFDFDFDFDFD0000ULL,
1305 0xFDFDFDFDFDFDFD00ULL,
1306 0xFDFDFDFDFDFDFDFDULL,
1307 0xFDFDFDFDFDFDFDFDULL,
1308 0xFDFDFDFDFDFDFDFDULL
1309 },
1310 {
1311 0xFDFDFDFD00000000ULL,
1312 0xFDFDFDFDFD000000ULL,
1313 0xFDFDFDFDFDFD0000ULL,
1314 0xFDFDFDFDFDFDFD00ULL,
1315 0xFDFDFDFDFDFDFDFDULL,
1316 0xFDFDFDFDFDFDFDFDULL,
1317 0xFDFDFDFDFDFDFDFDULL,
1318 0xFDFDFDFDFDFDFDFDULL
1319 },
1320 {
1321 0xFDFDFDFDFD000000ULL,
1322 0xFDFDFDFDFDFD0000ULL,
1323 0xFDFDFDFDFDFDFD00ULL,
1324 0xFDFDFDFDFDFDFDFDULL,
1325 0xFDFDFDFDFDFDFDFDULL,
1326 0xFDFDFDFDFDFDFDFDULL,
1327 0xFDFDFDFDFDFDFDFDULL,
1328 0xFDFDFDFDFDFDFDFDULL
1329 },
1330 {
1331 0xFDFDFDFDFDFD0000ULL,
1332 0xFDFDFDFDFDFDFD00ULL,
1333 0xFDFDFDFDFDFDFDFDULL,
1334 0xFDFDFDFDFDFDFDFDULL,
1335 0xFDFDFDFDFDFDFDFDULL,
1336 0xFDFDFDFDFDFDFDFDULL,
1337 0xFDFDFDFDFDFDFDFDULL,
1338 0xFDFDFDFDFDFDFDFDULL
1339 },
1340 {
1341 0xFDFDFDFDFDFDFD00ULL,
1342 0xFDFDFDFDFDFDFDFDULL,
1343 0xFDFDFDFDFDFDFDFDULL,
1344 0xFDFDFDFDFDFDFDFDULL,
1345 0xFDFDFDFDFDFDFDFDULL,
1346 0xFDFDFDFDFDFDFDFDULL,
1347 0xFDFDFDFDFDFDFDFDULL,
1348 0xFDFDFDFDFDFDFDFDULL
1349 },
1350 {
1351 0xFDFDFDFDFDFDFDFDULL,
1352 0xFDFDFDFDFDFDFDFDULL,
1353 0xFDFDFDFDFDFDFDFDULL,
1354 0xFDFDFDFDFDFDFDFDULL,
1355 0xFDFDFDFDFDFDFDFDULL,
1356 0xFDFDFDFDFDFDFDFDULL,
1357 0xFDFDFDFDFDFDFDFDULL,
1358 0xFDFDFDFDFDFDFDFDULL
1359 }
1360 },
1361 {
1362 {
1363 0x0000000000000000ULL,
1364 0x0000000000000000ULL,
1365 0x0000000000000000ULL,
1366 0x0000000000000000ULL,
1367 0x0000000000000000ULL,
1368 0x0000000000000000ULL,
1369 0x0000000000000000ULL,
1370 0x0000000000000000ULL
1371 },
1372 {
1373 0x0000000000000000ULL,
1374 0x0000000000000000ULL,
1375 0x0000000000000000ULL,
1376 0x0000000000000000ULL,
1377 0x0000000000000000ULL,
1378 0x0000000000000000ULL,
1379 0x0000000000000000ULL,
1380 0x00000000000000FDULL
1381 },
1382 {
1383 0x0000000000000000ULL,
1384 0x0000000000000000ULL,
1385 0x0000000000000000ULL,
1386 0x0000000000000000ULL,
1387 0x0000000000000000ULL,
1388 0x0000000000000000ULL,
1389 0x00000000000000FDULL,
1390 0x000000000000FDFDULL
1391 },
1392 {
1393 0x0000000000000000ULL,
1394 0x0000000000000000ULL,
1395 0x0000000000000000ULL,
1396 0x0000000000000000ULL,
1397 0x0000000000000000ULL,
1398 0x00000000000000FDULL,
1399 0x000000000000FDFDULL,
1400 0x0000000000FDFDFDULL
1401 },
1402 {
1403 0x0000000000000000ULL,
1404 0x0000000000000000ULL,
1405 0x0000000000000000ULL,
1406 0x0000000000000000ULL,
1407 0x00000000000000FDULL,
1408 0x000000000000FDFDULL,
1409 0x0000000000FDFDFDULL,
1410 0x00000000FDFDFDFDULL
1411 },
1412 {
1413 0x0000000000000000ULL,
1414 0x0000000000000000ULL,
1415 0x0000000000000000ULL,
1416 0x00000000000000FDULL,
1417 0x000000000000FDFDULL,
1418 0x0000000000FDFDFDULL,
1419 0x00000000FDFDFDFDULL,
1420 0x000000FDFDFDFDFDULL
1421 },
1422 {
1423 0x0000000000000000ULL,
1424 0x0000000000000000ULL,
1425 0x00000000000000FDULL,
1426 0x000000000000FDFDULL,
1427 0x0000000000FDFDFDULL,
1428 0x00000000FDFDFDFDULL,
1429 0x000000FDFDFDFDFDULL,
1430 0x0000FDFDFDFDFDFDULL
1431 },
1432 {
1433 0x0000000000000000ULL,
1434 0x00000000000000FDULL,
1435 0x000000000000FDFDULL,
1436 0x0000000000FDFDFDULL,
1437 0x00000000FDFDFDFDULL,
1438 0x000000FDFDFDFDFDULL,
1439 0x0000FDFDFDFDFDFDULL,
1440 0x00FDFDFDFDFDFDFDULL
1441 },
1442 {
1443 0x00000000000000FDULL,
1444 0x000000000000FDFDULL,
1445 0x0000000000FDFDFDULL,
1446 0x00000000FDFDFDFDULL,
1447 0x000000FDFDFDFDFDULL,
1448 0x0000FDFDFDFDFDFDULL,
1449 0x00FDFDFDFDFDFDFDULL,
1450 0xFDFDFDFDFDFDFDFDULL
1451 },
1452 {
1453 0x000000000000FDFDULL,
1454 0x0000000000FDFDFDULL,
1455 0x00000000FDFDFDFDULL,
1456 0x000000FDFDFDFDFDULL,
1457 0x0000FDFDFDFDFDFDULL,
1458 0x00FDFDFDFDFDFDFDULL,
1459 0xFDFDFDFDFDFDFDFDULL,
1460 0xFDFDFDFDFDFDFDFDULL
1461 },
1462 {
1463 0x0000000000FDFDFDULL,
1464 0x00000000FDFDFDFDULL,
1465 0x000000FDFDFDFDFDULL,
1466 0x0000FDFDFDFDFDFDULL,
1467 0x00FDFDFDFDFDFDFDULL,
1468 0xFDFDFDFDFDFDFDFDULL,
1469 0xFDFDFDFDFDFDFDFDULL,
1470 0xFDFDFDFDFDFDFDFDULL
1471 },
1472 {
1473 0x00000000FDFDFDFDULL,
1474 0x000000FDFDFDFDFDULL,
1475 0x0000FDFDFDFDFDFDULL,
1476 0x00FDFDFDFDFDFDFDULL,
1477 0xFDFDFDFDFDFDFDFDULL,
1478 0xFDFDFDFDFDFDFDFDULL,
1479 0xFDFDFDFDFDFDFDFDULL,
1480 0xFDFDFDFDFDFDFDFDULL
1481 },
1482 {
1483 0x000000FDFDFDFDFDULL,
1484 0x0000FDFDFDFDFDFDULL,
1485 0x00FDFDFDFDFDFDFDULL,
1486 0xFDFDFDFDFDFDFDFDULL,
1487 0xFDFDFDFDFDFDFDFDULL,
1488 0xFDFDFDFDFDFDFDFDULL,
1489 0xFDFDFDFDFDFDFDFDULL,
1490 0xFDFDFDFDFDFDFDFDULL
1491 },
1492 {
1493 0x0000FDFDFDFDFDFDULL,
1494 0x00FDFDFDFDFDFDFDULL,
1495 0xFDFDFDFDFDFDFDFDULL,
1496 0xFDFDFDFDFDFDFDFDULL,
1497 0xFDFDFDFDFDFDFDFDULL,
1498 0xFDFDFDFDFDFDFDFDULL,
1499 0xFDFDFDFDFDFDFDFDULL,
1500 0xFDFDFDFDFDFDFDFDULL
1501 },
1502 {
1503 0x00FDFDFDFDFDFDFDULL,
1504 0xFDFDFDFDFDFDFDFDULL,
1505 0xFDFDFDFDFDFDFDFDULL,
1506 0xFDFDFDFDFDFDFDFDULL,
1507 0xFDFDFDFDFDFDFDFDULL,
1508 0xFDFDFDFDFDFDFDFDULL,
1509 0xFDFDFDFDFDFDFDFDULL,
1510 0xFDFDFDFDFDFDFDFDULL
1511 },
1512 {
1513 0xFDFDFDFDFDFDFDFDULL,
1514 0xFDFDFDFDFDFDFDFDULL,
1515 0xFDFDFDFDFDFDFDFDULL,
1516 0xFDFDFDFDFDFDFDFDULL,
1517 0xFDFDFDFDFDFDFDFDULL,
1518 0xFDFDFDFDFDFDFDFDULL,
1519 0xFDFDFDFDFDFDFDFDULL,
1520 0xFDFDFDFDFDFDFDFDULL
1521 }
1522 }
1523 };
1524
1525 int32_t black_opening_count=0;
1526 int32_t black_opening_x,black_opening_y;
1527 int32_t black_opening_shape;
1528
1529 3197 int32_t choose_opening_shape()
1530 {
1531 // First, count how many bits are set
1532 3197 int32_t numBits=0;
1533 int32_t bitCounter;
1534
1535
2/2
✓ Branch 0 taken 15985 times.
✓ Branch 1 taken 3197 times.
19182 for(int32_t i=0; i<bosMAX; i++)
1536 {
1537
2/2
✓ Branch 0 taken 12572 times.
✓ Branch 1 taken 3413 times.
15985 if(COOLSCROLL&(1<<i))
1538 3413 numBits++;
1539 15985 }
1540
1541 // Shouldn't happen...
1542
1/2
✓ Branch 0 taken 3197 times.
✗ Branch 1 not taken.
3197 if(numBits==0)
1543 return bosCIRCLE;
1544
1545 // Pick a bit
1546 3197 bitCounter=zc_rand()%numBits+1;
1547
1548
2/2
✓ Branch 0 taken 4388 times.
✓ Branch 1 taken 26 times.
4414 for(int32_t i=0; i<bosMAX; i++)
1549 {
1550 // If this bit is set, decrement the bit counter
1551
2/2
✓ Branch 0 taken 1061 times.
✓ Branch 1 taken 3327 times.
4388 if(COOLSCROLL&(1<<i))
1552 3327 bitCounter--;
1553
1554 // When the counter hits 0, return a value based on
1555 // which bit it stopped on.
1556 // Reminder: enum {bosCIRCLE=0, bosOVAL, bosTRIANGLE, bosSMAS, bosFADEBLACK, bosMAX};
1557
2/2
✓ Branch 0 taken 3171 times.
✓ Branch 1 taken 1217 times.
4388 if(bitCounter==0)
1558 3171 return i;
1559 1217 }
1560
1561 // Shouldn't be necessary, but the compiler might complain, at least
1562 26 return bosCIRCLE;
1563 3197 }
1564
1565 727 void close_black_opening(int32_t x, int32_t y, bool wait, int32_t shape)
1566 {
1567
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 727 times.
727 black_opening_shape= (shape>-1 ? shape : choose_opening_shape());
1568
1569 727 int32_t w=256, h=224;
1570 727 int32_t blockrows=28, blockcolumns=32;
1571 727 int32_t xoffset=(x-(w/2))/8, yoffset=(y-(h/2))/8;
1572
1573
2/2
✓ Branch 0 taken 20356 times.
✓ Branch 1 taken 727 times.
21083 for(int32_t blockrow=0; blockrow<blockrows; ++blockrow) //30
1574 {
1575
2/2
✓ Branch 0 taken 651392 times.
✓ Branch 1 taken 20356 times.
671748 for(int32_t blockcolumn=0; blockcolumn<blockcolumns; ++blockcolumn) //40
1576 {
1577
2/2
✓ Branch 0 taken 269309 times.
✓ Branch 1 taken 382083 times.
651392 screen_triangles[blockrow][blockcolumn]=zc_max(abs(int32_t(double(blockcolumns-1)/2-blockcolumn+xoffset)),abs(int32_t(double(blockrows-1)/2-blockrow+yoffset)))|0x0100|((blockrow-yoffset<blockrows/2)?0:0x8000)|((blockcolumn-xoffset<blockcolumns/2)?0x4000:0);
1578 651392 }
1579 20356 }
1580
1581 727 black_opening_count = 66;
1582 727 black_opening_x = x;
1583 727 black_opening_y = y;
1584 727 lensclk = 0;
1585 //black_opening_shape=(black_opening_shape+1)%bosMAX;
1586
1587
1588
1/2
✓ Branch 0 taken 727 times.
✗ Branch 1 not taken.
727 if(black_opening_shape == bosFADEBLACK)
1589 {
1590 refreshTints();
1591 memcpy(tempblackpal, RAMpal, sizeof(RAMpal)); //Store palette in temp palette for fade effect
1592 }
1593
2/2
✓ Branch 0 taken 723 times.
✓ Branch 1 taken 4 times.
727 if(wait)
1594 {
1595 4 FFCore.warpScriptCheck();
1596
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 264 times.
268 for(int32_t i=0; i<66; i++)
1597 {
1598 264 draw_screen(tmpscr);
1599 //put_passive_subscr(framebuf,0,passive_subscreen_offset,false,sspUP);
1600 264 advanceframe(true);
1601
1602
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 264 times.
264 if(Quit)
1603 {
1604 break;
1605 }
1606 264 }
1607 4 }
1608 727 }
1609
1610 2470 void open_black_opening(int32_t x, int32_t y, bool wait, int32_t shape)
1611 {
1612
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2470 times.
2470 black_opening_shape= (shape>-1 ? shape : choose_opening_shape());
1613
1614 2470 int32_t w=256, h=224;
1615 2470 int32_t blockrows=28, blockcolumns=32;
1616 2470 int32_t xoffset=(x-(w/2))/8, yoffset=(y-(h/2))/8;
1617
1618
2/2
✓ Branch 0 taken 69160 times.
✓ Branch 1 taken 2470 times.
71630 for(int32_t blockrow=0; blockrow<blockrows; ++blockrow) //30
1619 {
1620
2/2
✓ Branch 0 taken 2213120 times.
✓ Branch 1 taken 69160 times.
2282280 for(int32_t blockcolumn=0; blockcolumn<blockcolumns; ++blockcolumn) //40
1621 {
1622
2/2
✓ Branch 0 taken 1092294 times.
✓ Branch 1 taken 1120826 times.
2213120 screen_triangles[blockrow][blockcolumn]=zc_max(abs(int32_t(double(blockcolumns-1)/2-blockcolumn+xoffset)),abs(int32_t(double(blockrows-1)/2-blockrow+yoffset)))|0x0100|((blockrow-yoffset<blockrows/2)?0:0x8000)|((blockcolumn-xoffset<blockcolumns/2)?0x4000:0);
1623 2213120 }
1624 69160 }
1625
1626 2470 black_opening_count = -66;
1627 2470 black_opening_x = x;
1628 2470 black_opening_y = y;
1629 2470 lensclk = 0;
1630
1/2
✓ Branch 0 taken 2470 times.
✗ Branch 1 not taken.
2470 if(black_opening_shape == bosFADEBLACK)
1631 {
1632 refreshTints();
1633 memcpy(tempblackpal, RAMpal, sizeof(RAMpal)); //Store palette in temp palette for fade effect
1634 }
1635
2/2
✓ Branch 0 taken 367 times.
✓ Branch 1 taken 2103 times.
2470 if(wait)
1636 {
1637 2103 FFCore.warpScriptCheck();
1638
2/2
✓ Branch 0 taken 2102 times.
✓ Branch 1 taken 138801 times.
140903 for(int32_t i=0; i<66; i++)
1639 {
1640 138801 draw_screen(tmpscr);
1641 //put_passive_subscr(framebuf,0,passive_subscreen_offset,false,sspUP);
1642 138801 advanceframe(true);
1643
1644
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 138800 times.
138801 if(Quit)
1645 {
1646 1 break;
1647 }
1648 138800 }
1649 2103 }
1650 2470 }
1651
1652 210291 void black_opening(BITMAP *dest,int32_t x,int32_t y,int32_t a,int32_t max_a)
1653 {
1654 210291 clear_to_color(tmp_scr,BLACK);
1655 210291 int32_t w=256, h=224;
1656
1657
4/6
✗ Branch 0 not taken.
✓ Branch 1 taken 9636 times.
✓ Branch 2 taken 660 times.
✓ Branch 3 taken 20262 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 179733 times.
210291 switch(black_opening_shape)
1658 {
1659 case bosOVAL:
1660 {
1661 9636 double new_w=(w/2)+abs(w/2-x);
1662 9636 double new_h=(h/2)+abs(h/2-y);
1663 9636 double b=sqrt(((new_w*new_w)/4)+(new_h*new_h));
1664 9636 ellipsefill(tmp_scr,x,y,int32_t(2*a*b/max_a)/8*8,int32_t(a*b/max_a)/8*8,0);
1665 9636 break;
1666 }
1667
1668 case bosTRIANGLE:
1669 {
1670 660 double new_w=(w/2)+abs(w/2-x);
1671 660 double new_h=(h/2)+abs(h/2-y);
1672 660 double r=a*(new_w*sqrt((double)3)+new_h)/max_a;
1673 660 double P2= (PI/2);
1674 660 double P23=(2*PI/3);
1675 660 double P43=(4*PI/3);
1676 660 double Pa= (-4*PI*a/(3*max_a));
1677 660 double angle=P2+Pa;
1678 660 double a0=angle;
1679 660 double a2=angle+P23;
1680 660 double a4=angle+P43;
1681 1320 triangle(tmp_scr, x+int32_t(zc::math::Cos(a0)*r), y-int32_t(zc::math::Sin(a0)*r),
1682 660 x+int32_t(zc::math::Cos(a2)*r), y-int32_t(zc::math::Sin(a2)*r),
1683 660 x+int32_t(zc::math::Cos(a4)*r), y-int32_t(zc::math::Sin(a4)*r),
1684 0);
1685 660 break;
1686 }
1687
1688 case bosSMAS:
1689 {
1690
2/2
✓ Branch 0 taken 7194 times.
✓ Branch 1 taken 13068 times.
20262 int32_t distance=zc_max(abs(w/2-x),abs(h/2-y))/8;
1691
1692
2/2
✓ Branch 0 taken 567336 times.
✓ Branch 1 taken 20262 times.
587598 for(int32_t blockrow=0; blockrow<28; ++blockrow) //30
1693 {
1694
2/2
✓ Branch 0 taken 4538688 times.
✓ Branch 1 taken 567336 times.
5106024 for(int32_t linerow=0; linerow<8; ++linerow)
1695 {
1696 4538688 qword *triangleline=(qword*)(tmp_scr->line[(blockrow*8+linerow)]);
1697
1698
2/2
✓ Branch 0 taken 145238016 times.
✓ Branch 1 taken 4538688 times.
149776704 for(int32_t blockcolumn=0; blockcolumn<32; ++blockcolumn) //40
1699 {
1700 435714048 *triangleline=triangles[(screen_triangles[blockrow][blockcolumn]&0xC000)>>14]
1701
6/6
✓ Branch 0 taken 104912184 times.
✓ Branch 1 taken 40325832 times.
✓ Branch 2 taken 95821040 times.
✓ Branch 3 taken 49416976 times.
✓ Branch 4 taken 55495208 times.
✓ Branch 5 taken 40325832 times.
145238016 [zc_min(zc_max((((31+distance)*(max_a-a)/max_a)+((screen_triangles[blockrow][blockcolumn]&0x0FFF)-0x0100)-(15+distance)),0),15)]
1702 145238016 [linerow];
1703 145238016 ++triangleline;
1704
1705
2/2
✓ Branch 0 taken 127083264 times.
✓ Branch 1 taken 18154752 times.
145238016 if(linerow==0)
1706 {
1707 18154752 }
1708 145238016 }
1709 4538688 }
1710 567336 }
1711
1712 20262 break;
1713 }
1714
1715 case bosFADEBLACK:
1716 {
1717 if(black_opening_count<0)
1718 {
1719 black_fade(zc_min(-black_opening_count,63));
1720 }
1721 else if(black_opening_count>0)
1722 {
1723 black_fade(63-zc_max(black_opening_count-3,0));
1724 }
1725 else black_fade(0);
1726 return; //no blitting from tmp_scr!
1727 }
1728
1729 179733 case bosCIRCLE:
1730 default:
1731 {
1732 179733 double new_w=(w/2)+abs(w/2-x);
1733 179733 double new_h=(h/2)+abs(h/2-y);
1734 179733 int32_t r=int32_t(sqrt((new_w*new_w)+(new_h*new_h))*a/max_a);
1735 //circlefill(tmp_scr,x,y,a<<3,0);
1736 179733 circlefill(tmp_scr,x,y,r,0);
1737 179733 break;
1738 }
1739 }
1740
1741 210291 masked_blit(tmp_scr,dest,0,0,0,0,320,240);
1742 210291 }
1743
1744 // fadeamnt is 0-63
1745 void black_fade(int32_t fadeamnt)
1746 {
1747 fadeamnt = _rgb_scale_6[fadeamnt];
1748 for(int32_t i=0; i < 0xEF; i++)
1749 {
1750 RAMpal[i].r = vbound(tempblackpal[i].r-fadeamnt,0,255);
1751 RAMpal[i].g = vbound(tempblackpal[i].g-fadeamnt,0,255);
1752 RAMpal[i].b = vbound(tempblackpal[i].b-fadeamnt,0,255);
1753 }
1754
1755 refreshpal = true;
1756 }
1757
1758 //----------------------------------------------------------------
1759
1760 197795172 bool item_disabled(int32_t item) //is this item disabled?
1761 {
1762
2/2
✓ Branch 0 taken 13811961 times.
✓ Branch 1 taken 183983211 times.
197795172 return (unsigned(item) < MAXITEMS && game->items_off[item] != 0);
1763 }
1764
1765 15435195 bool can_use_item(int32_t item_type, int32_t item) //can Hero use this item?
1766 {
1767
2/2
✓ Branch 0 taken 188072 times.
✓ Branch 1 taken 15247123 times.
15435195 if(current_item(item_type, true) >=item)
1768 {
1769 188072 return true;
1770 }
1771
1772 15247123 return false;
1773 15435195 }
1774
1775 48030228 bool has_item(int32_t item_type, int32_t it) //does Hero possess this item?
1776 {
1777
5/9
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 4372047 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4901587 times.
✓ Branch 6 taken 28670023 times.
✓ Branch 7 taken 9892117 times.
✓ Branch 8 taken 194454 times.
48030228 switch(item_type)
1778 {
1779 case itype_bomb:
1780 case itype_sbomb:
1781 {
1782 int32_t itemid = getItemID(itemsbuf, item_type, it);
1783
1784 if(itemid == -1)
1785 return false;
1786
1787 return (game->get_item(itemid));
1788 }
1789
1790 case itype_clock:
1791 {
1792 4372047 int32_t itemid = getItemID(itemsbuf, item_type, it);
1793
1794
2/4
✓ Branch 0 taken 4372047 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4372047 times.
✗ Branch 3 not taken.
4372047 if(itemid != -1 && (itemsbuf[itemid].flags & item_flag1)) //Active clock
1795 return (game->get_item(itemid));
1796 4372047 return Hero.getClock()?1:0;
1797 }
1798
1799 case itype_key:
1800 return (game->get_keys()>0);
1801
1802 case itype_magiccontainer:
1803 return (game->get_maxmagic()>=game->get_mp_per_block());
1804
1805 case itype_triforcepiece: //it: -2=any, -1=current level, other=that level
1806 {
1807
2/3
✓ Branch 0 taken 321216 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4580371 times.
4901587 switch(it)
1808 {
1809 case -2:
1810 {
1811 for(int32_t i=0; i<MAXLEVELS; i++)
1812 {
1813 if(game->lvlitems[i]&liTRIFORCE)
1814 {
1815 return true;
1816 }
1817 }
1818
1819 return false;
1820 }
1821
1822 case -1:
1823 4580371 return (game->lvlitems[dlevel]&liTRIFORCE);
1824
1825 default:
1826
2/4
✓ Branch 0 taken 321216 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 321216 times.
321216 if(it>=0&&it<MAXLEVELS)
1827 {
1828 321216 return (game->lvlitems[it]&liTRIFORCE);
1829 }
1830
1831 break;
1832 }
1833
1834 return 0;
1835 }
1836
1837 case itype_map: //it: -2=any, -1=current level, other=that level
1838 {
1839
2/3
✓ Branch 0 taken 540402 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 28129621 times.
28670023 switch(it)
1840 {
1841 case -2:
1842 {
1843 for(int32_t i=0; i<MAXLEVELS; i++)
1844 {
1845 if(game->lvlitems[i]&liMAP)
1846 {
1847 return true;
1848 }
1849 }
1850
1851 return false;
1852 }
1853
1854 case -1:
1855 28129621 return (game->lvlitems[dlevel]&liMAP)!=0;
1856
1857 default:
1858
2/4
✓ Branch 0 taken 540402 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 540402 times.
540402 if(it>=0&&it<MAXLEVELS)
1859 {
1860 540402 return (game->lvlitems[it]&liMAP)!=0;
1861 }
1862
1863 break;
1864 }
1865
1866 return 0;
1867 }
1868
1869 case itype_compass: //it: -2=any, -1=current level, other=that level
1870 {
1871
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 9892117 times.
9892117 switch(it)
1872 {
1873 case -2:
1874 {
1875 for(int32_t i=0; i<MAXLEVELS; i++)
1876 {
1877 if(game->lvlitems[i]&liCOMPASS)
1878 {
1879 return true;
1880 }
1881 }
1882
1883 return false;
1884 }
1885
1886 case -1:
1887 9892117 return (game->lvlitems[dlevel]&liCOMPASS)!=0;
1888
1889 default:
1890 if(it>=0&&it<MAXLEVELS)
1891 {
1892 return (game->lvlitems[it]&liCOMPASS)!=0;
1893 }
1894
1895 break;
1896 }
1897 return 0;
1898 }
1899
1900 case itype_bosskey: //it: -2=any, -1=current level, other=that level
1901 {
1902
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 194454 times.
194454 switch(it)
1903 {
1904 case -2:
1905 {
1906 for(int32_t i=0; i<MAXLEVELS; i++)
1907 {
1908 if(game->lvlitems[i]&liBOSSKEY)
1909 {
1910 return true;
1911 }
1912 }
1913
1914 return false;
1915 }
1916
1917 case -1:
1918 194454 return (game->lvlitems[dlevel]&liBOSSKEY)?1:0;
1919
1920 default:
1921 if(it>=0&&it<MAXLEVELS)
1922 {
1923 return (game->lvlitems[it]&liBOSSKEY)?1:0;
1924 }
1925 break;
1926 }
1927 return 0;
1928 }
1929
1930 default:
1931 int32_t itemid = getItemID(itemsbuf, item_type, it);
1932
1933 if(itemid == -1)
1934 return false;
1935
1936 return game->get_item(itemid);
1937 }
1938 48030228 }
1939
1940 149096295 int current_item(int item_type, bool checkmagic, bool jinx_check, bool check_bunny)
1941 {
1942
9/9
✓ Branch 0 taken 4372047 times.
✓ Branch 1 taken 114119919 times.
✓ Branch 2 taken 4372047 times.
✓ Branch 3 taken 4372047 times.
✓ Branch 4 taken 4372047 times.
✓ Branch 5 taken 4372047 times.
✓ Branch 6 taken 4372047 times.
✓ Branch 7 taken 4372047 times.
✓ Branch 8 taken 4372047 times.
149096295 switch(item_type)
1943 {
1944 case itype_clock:
1945 {
1946 4372047 int maxid = current_item_id(item_type, checkmagic, jinx_check, check_bunny);
1947
1948
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 4372047 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
4372047 if(maxid != -1 && (itemsbuf[maxid].flags & item_flag1)) //Active clock
1949 return itemsbuf[maxid].fam_type;
1950
1951 4372047 return has_item(itype_clock,1) ? 1 : 0;
1952 }
1953
1954 case itype_key:
1955 4372047 return game->get_keys();
1956
1957 case itype_lkey:
1958 4372047 return game->lvlkeys[get_dlevel()];
1959
1960 case itype_magiccontainer:
1961 4372047 return game->get_maxmagic()/game->get_mp_per_block();
1962
1963 case itype_triforcepiece:
1964 {
1965 4372047 int count=0;
1966
1967
2/2
✓ Branch 0 taken 2238488064 times.
✓ Branch 1 taken 4372047 times.
2242860111 for(int i=0; i<MAXLEVELS; i++)
1968 {
1969 2238488064 count+=(game->lvlitems[i]&liTRIFORCE)?1:0;
1970 2238488064 }
1971
1972 4372047 return count;
1973 }
1974
1975 case itype_map:
1976 {
1977 4372047 int count=0;
1978
1979
2/2
✓ Branch 0 taken 2238488064 times.
✓ Branch 1 taken 4372047 times.
2242860111 for(int i=0; i<MAXLEVELS; i++)
1980 {
1981 2238488064 count+=(game->lvlitems[i]&liMAP)?1:0;
1982 2238488064 }
1983
1984 4372047 return count;
1985 }
1986
1987 case itype_compass:
1988 {
1989 4372047 int count=0;
1990
1991
2/2
✓ Branch 0 taken 2238488064 times.
✓ Branch 1 taken 4372047 times.
2242860111 for(int i=0; i<MAXLEVELS; i++)
1992 {
1993 2238488064 count+=(game->lvlitems[i]&liCOMPASS)?1:0;
1994 2238488064 }
1995
1996 4372047 return count;
1997 }
1998
1999 case itype_bosskey:
2000 {
2001 4372047 int count=0;
2002
2003
2/2
✓ Branch 0 taken 2238488064 times.
✓ Branch 1 taken 4372047 times.
2242860111 for(int i=0; i<MAXLEVELS; i++)
2004 {
2005 2238488064 count+=(game->lvlitems[i]&liBOSSKEY)?1:0;
2006 2238488064 }
2007
2008 4372047 return count;
2009 }
2010
2011 default:
2012 114119919 int maxid = current_item_id(item_type, checkmagic, jinx_check, check_bunny);
2013
2014
2/2
✓ Branch 0 taken 81094879 times.
✓ Branch 1 taken 33025040 times.
114119919 if(maxid == -1)
2015 81094879 return 0;
2016
2017 33025040 return itemsbuf[maxid].fam_type;
2018 }
2019 149096295 }
2020
2021 329 std::map<int32_t, int32_t> itemcache;
2022 329 std::map<int32_t, int32_t> itemcache_cost;
2023
2024 void removeFromItemCache(int32_t itemclass)
2025 {
2026 itemcache.erase(itemclass);
2027 itemcache_cost.erase(itemclass);
2028 cache_tile_mod_clear();
2029 }
2030
2031 12386031 void flushItemCache(bool justcost)
2032 {
2033 12386031 itemcache_cost.clear();
2034
2/2
✓ Branch 0 taken 12319820 times.
✓ Branch 1 taken 66211 times.
12386031 if(!justcost)
2035 66211 itemcache.clear();
2036
2/2
✓ Branch 0 taken 5825976 times.
✓ Branch 1 taken 6493844 times.
12319820 else if(replay_version_check(0,19))
2037 5825976 return;
2038
2039 6560055 cache_tile_mod_clear();
2040
2041 //also fix the active subscreen if items were deleted -DD
2042
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6560055 times.
6560055 if(game != NULL)
2043 {
2044 6560055 verifyBothWeapons();
2045 6560055 refresh_subscr_items();
2046 6560055 }
2047 12386031 }
2048
2049 // This is used often, so it should be as direct as possible.
2050 2945792204 int _c_item_id_internal(int itemtype, bool checkmagic, bool jinx_check, bool check_bunny)
2051 {
2052 2945792204 bool use_cost_cache = replay_version_check(19);
2053
2/2
✓ Branch 0 taken 2821606919 times.
✓ Branch 1 taken 124185285 times.
2945792204 if(jinx_check)
2054 {
2055 //special case for shields...
2056
3/4
✓ Branch 0 taken 39598597 times.
✓ Branch 1 taken 84586688 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 39598597 times.
124185285 if (itemtype == itype_shield && !HeroShieldClk())
2057 39598597 jinx_check = false;
2058
4/4
✓ Branch 0 taken 52047844 times.
✓ Branch 1 taken 32538844 times.
✓ Branch 2 taken 10855064 times.
✓ Branch 3 taken 41192780 times.
84586688 else if(!(HeroSwordClk() || HeroItemClk()))
2059 41192780 jinx_check = false; //not jinxed
2060 124185285 }
2061
4/4
✓ Branch 0 taken 103098 times.
✓ Branch 1 taken 2945689106 times.
✓ Branch 2 taken 1853 times.
✓ Branch 3 taken 101245 times.
2945792204 if(!Hero.BunnyClock() || itemtype == itype_pearl) // bunny_check does not apply
2062 2945690959 check_bunny = false;
2063
2/2
✓ Branch 0 taken 2889944326 times.
✓ Branch 1 taken 55847878 times.
2945792204 if(itemtype == itype_ring) checkmagic = true;
2064
4/4
✓ Branch 0 taken 2902398296 times.
✓ Branch 1 taken 43393908 times.
✓ Branch 2 taken 274567871 times.
✓ Branch 3 taken 23758619 times.
3244118694 if (!jinx_check && !check_bunny
2065
4/4
✓ Branch 0 taken 2902319049 times.
✓ Branch 1 taken 79247 times.
✓ Branch 2 taken 298326490 times.
✓ Branch 3 taken 2603992559 times.
2902398296 && (use_cost_cache || itemtype != itype_ring))
2066 {
2067
4/4
✓ Branch 0 taken 533237469 times.
✓ Branch 1 taken 2345322961 times.
✓ Branch 2 taken 232758434 times.
✓ Branch 3 taken 300479035 times.
2878560430 auto& cache = checkmagic && use_cost_cache ? itemcache_cost : itemcache;
2068 2878560430 auto res = cache.find(itemtype);
2069
2070
2/2
✓ Branch 0 taken 2735031850 times.
✓ Branch 1 taken 143528580 times.
2878560430 if(res != cache.end())
2071 2735031850 return res->second;
2072 143528580 }
2073
2074 210760354 int result = -1;
2075 210760354 int highestlevel = -1;
2076
2077
2/2
✓ Branch 0 taken 53954650624 times.
✓ Branch 1 taken 210760354 times.
54165410978 for(int i=0; i<MAXITEMS; i++)
2078 {
2079
6/6
✓ Branch 0 taken 5919641585 times.
✓ Branch 1 taken 48035009039 times.
✓ Branch 2 taken 95475753 times.
✓ Branch 3 taken 5824165832 times.
✓ Branch 4 taken 82048 times.
✓ Branch 5 taken 95393705 times.
53954650624 if(game->get_item(i) && itemsbuf[i].family==itemtype && !item_disabled(i))
2080 {
2081
4/4
✓ Branch 0 taken 90781743 times.
✓ Branch 1 taken 4611962 times.
✓ Branch 2 taken 2425909 times.
✓ Branch 3 taken 88355834 times.
95393705 if(checkmagic && itemtype != itype_magicring)
2082
2/2
✓ Branch 0 taken 88355217 times.
✓ Branch 1 taken 617 times.
88355834 if(!checkmagiccost(i))
2083 617 continue;
2084
6/6
✓ Branch 0 taken 87818658 times.
✓ Branch 1 taken 7574430 times.
✓ Branch 2 taken 1253626 times.
✓ Branch 3 taken 6320804 times.
✓ Branch 4 taken 4128291 times.
✓ Branch 5 taken 3446139 times.
95393088 if(jinx_check && (usesSwordJinx(i) ? HeroSwordClk() : HeroItemClk()))
2085
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3446139 times.
3446139 if(!(itemsbuf[i].flags & item_jinx_immune))
2086 3446139 continue;
2087
3/4
✓ Branch 0 taken 86055 times.
✓ Branch 1 taken 91860894 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 86055 times.
91946949 if(check_bunny && !checkbunny(i))
2088 86055 continue;
2089
2090
2/2
✓ Branch 0 taken 8380446 times.
✓ Branch 1 taken 83480448 times.
91860894 if(itemsbuf[i].fam_type >= highestlevel)
2091 {
2092 83480448 highestlevel = itemsbuf[i].fam_type;
2093 83480448 result=i;
2094 83480448 }
2095 91860894 }
2096 53951117813 }
2097
2098
4/4
✓ Branch 0 taken 167366446 times.
✓ Branch 1 taken 43393908 times.
✓ Branch 2 taken 79247 times.
✓ Branch 3 taken 167287199 times.
210760354 if(!(jinx_check || check_bunny)) //Can't cache jinx_check/check_bunny
2099 {
2100
2/2
✓ Branch 0 taken 127534263 times.
✓ Branch 1 taken 39752936 times.
167287199 if (use_cost_cache)
2101 {
2102
2/2
✓ Branch 0 taken 111812473 times.
✓ Branch 1 taken 15721790 times.
127534263 if (!checkmagic)
2103 15721790 itemcache[itemtype] = result;
2104
6/6
✓ Branch 0 taken 15721790 times.
✓ Branch 1 taken 111812473 times.
✓ Branch 2 taken 659682 times.
✓ Branch 3 taken 15062108 times.
✓ Branch 4 taken 647053 times.
✓ Branch 5 taken 12629 times.
127534263 if (checkmagic || result < 0 || checkmagiccost(result))
2105 127521634 itemcache_cost[itemtype] = result;
2106 127534263 }
2107 else
2108 {
2109 39752936 itemcache[itemtype] = result;
2110 }
2111 167287199 }
2112 210760354 return result;
2113 2945792204 }
2114
2115 // 'jinx_check' indicates that the highest level item *immune to jinxes* should be returned.
2116 2902898424 int current_item_id(int itype, bool checkmagic, bool jinx_check, bool check_bunny)
2117 {
2118
2/4
✓ Branch 0 taken 2902898424 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2902898424 times.
2902898424 if(itype < 0 || itype >= itype_max) return -1;
2119
1/2
✓ Branch 0 taken 2902898424 times.
✗ Branch 1 not taken.
2902898424 if(game->OverrideItems[itype] > -2)
2120 {
2121 auto ovid = game->OverrideItems[itype];
2122 if(ovid < 0 || ovid >= MAXITEMS)
2123 return -1;
2124 if(itemsbuf[ovid].family == itype)
2125 {
2126 if(itype == itype_magicring)
2127 checkmagic = false;
2128 else if(itype == itype_ring)
2129 checkmagic = true;
2130
2131 if(checkmagic && !checkmagiccost(ovid))
2132 return -1;
2133
2134 if (jinx_check && !checkitem_jinx(ovid))
2135 {
2136 return -1;
2137 }
2138 return ovid;
2139 }
2140 }
2141 2902898424 auto ret = _c_item_id_internal(itype,checkmagic,jinx_check,check_bunny);
2142
2/2
✓ Branch 0 taken 81291505 times.
✓ Branch 1 taken 2821606919 times.
2902898424 if(!jinx_check) //If not already a jinx-immune-only check...
2143 {
2144 //And the player IS jinxed...
2145
2/2
✓ Branch 0 taken 2778713139 times.
✓ Branch 1 taken 42893780 times.
2821606919 if(HeroIsJinxed())
2146 {
2147 //Then do a jinx-immune-only check here
2148 42893780 auto ret2 = _c_item_id_internal(itype,checkmagic,true,check_bunny);
2149 //And *IF IT FINDS A VALID ITEM*, return that one instead! -Em
2150 //Should NOT need a compat rule, as this should always return -1 in old quests.
2151
2/2
✓ Branch 0 taken 3252908 times.
✓ Branch 1 taken 39640872 times.
42893780 if(ret2 > -1) return ret2;
2152 39640872 }
2153 2818354011 }
2154 2899645516 return ret;
2155 2902898424 }
2156
2157 46320960 int current_item_power(int itemtype, bool checkmagic, bool jinx_check, bool check_bunny)
2158 {
2159 46320960 int result = current_item_id(itemtype, checkmagic, jinx_check, check_bunny);
2160
2/2
✓ Branch 0 taken 26777218 times.
✓ Branch 1 taken 19543742 times.
46320960 return (result<0) ? 0 : itemsbuf[result].power;
2161 }
2162
2163 26 int32_t heart_container_id()
2164 {
2165
1/2
✓ Branch 0 taken 754 times.
✗ Branch 1 not taken.
754 for(int32_t i=0; i<MAXITEMS; i++)
2166 {
2167
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 728 times.
754 if(itemsbuf[i].family == itype_heartcontainer)
2168 {
2169 26 return i;
2170 }
2171 728 }
2172 return -1;
2173 26 }
2174
2175 struct tilemod_cache_state_t
2176 {
2177
6/6
✓ Branch 0 taken 4371692 times.
✓ Branch 1 taken 8392780 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 8392778 times.
✓ Branch 4 taken 353 times.
✓ Branch 5 taken 8392425 times.
21157252 bool operator==(const tilemod_cache_state_t&) const = default;
2178
2179 bool valid;
2180 bool bunny_clock;
2181 bool superman;
2182 int shield;
2183 };
2184 tilemod_cache_state_t tilemod_cache_state;
2185 int32_t tilemod_cache_value;
2186
2187 6561434 void cache_tile_mod_clear()
2188 {
2189 6561434 tilemod_cache_state = {false};
2190 6561434 }
2191
2192 12764472 int32_t item_tile_mod()
2193 {
2194 51057888 tilemod_cache_state_t state = {
2195 .valid = true,
2196 12764472 .bunny_clock = Hero.BunnyClock() != 0,
2197 12764472 .superman = Hero.superman,
2198 12764472 .shield = Hero.active_shield_id,
2199 };
2200
2/2
✓ Branch 0 taken 8392425 times.
✓ Branch 1 taken 4372047 times.
12764472 if (tilemod_cache_state == state)
2201 8392425 return tilemod_cache_value;
2202
2203 4372047 int32_t tile=0;
2204 4372047 bool check_bombcost = !get_qr(qr_BROKEN_BOMB_AMMO_COSTS);
2205
4/4
✓ Branch 0 taken 3958810 times.
✓ Branch 1 taken 413237 times.
✓ Branch 2 taken 3039600 times.
✓ Branch 3 taken 919210 times.
4372047 if(check_bombcost || game->get_bombs())
2206 {
2207 3452837 int32_t itemid = current_item_id(itype_bomb,check_bombcost);
2208
3/4
✓ Branch 0 taken 3393364 times.
✓ Branch 1 taken 59473 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3393364 times.
3452837 if(itemid > -1 && checkbunny(itemid))
2209 3393364 tile+=itemsbuf[itemid].ltm;
2210 3452837 }
2211
2212
4/4
✓ Branch 0 taken 3958810 times.
✓ Branch 1 taken 413237 times.
✓ Branch 2 taken 928295 times.
✓ Branch 3 taken 3030515 times.
4372047 if(check_bombcost || game->get_sbombs())
2213 {
2214 1341532 int32_t itemid = current_item_id(itype_sbomb,check_bombcost);
2215
3/4
✓ Branch 0 taken 928054 times.
✓ Branch 1 taken 413478 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 928054 times.
1341532 if(itemid > -1 && checkbunny(itemid))
2216 928054 tile+=itemsbuf[itemid].ltm;
2217 1341532 }
2218
2219
2/2
✓ Branch 0 taken 4367444 times.
✓ Branch 1 taken 4603 times.
4372047 if(current_item(itype_clock))
2220 {
2221 4603 int32_t itemid =
2222
2/2
✓ Branch 0 taken 4594 times.
✓ Branch 1 taken 9 times.
4603 get_qr(qr_HARDCODED_LITEM_LTMS)
2223 ? iClock
2224 9 : getHighestLevelEvenUnowned(itemsbuf, itype_clock);
2225
2/4
✓ Branch 0 taken 4603 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4603 times.
4603 if(itemid > -1 && checkbunny(itemid))
2226 4603 tile+=itemsbuf[itemid].ltm;
2227 4603 }
2228
2229
2/2
✓ Branch 0 taken 3763407 times.
✓ Branch 1 taken 608640 times.
4372047 if(current_item(itype_key))
2230 {
2231 608640 int32_t itemid =
2232
1/2
✓ Branch 0 taken 608640 times.
✗ Branch 1 not taken.
608640 get_qr(qr_HARDCODED_LITEM_LTMS)
2233 ? iKey
2234 : getHighestLevelEvenUnowned(itemsbuf, itype_key);
2235
2/4
✓ Branch 0 taken 608640 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 608640 times.
608640 if(itemid > -1 && checkbunny(itemid))
2236 608640 tile+=itemsbuf[itemid].ltm;
2237 608640 }
2238
2239
2/2
✓ Branch 0 taken 3871187 times.
✓ Branch 1 taken 500860 times.
4372047 if(current_item(itype_lkey))
2240 {
2241 500860 int32_t itemid =
2242
2/2
✓ Branch 0 taken 414146 times.
✓ Branch 1 taken 86714 times.
500860 get_qr(qr_HARDCODED_LITEM_LTMS)
2243 ? iLevelKey
2244 86714 : getHighestLevelEvenUnowned(itemsbuf, itype_lkey);
2245
2/4
✓ Branch 0 taken 500860 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 500860 times.
500860 if(itemid > -1 && checkbunny(itemid))
2246 500860 tile+=itemsbuf[itemid].ltm;
2247 500860 }
2248
2249
2/2
✓ Branch 0 taken 1537579 times.
✓ Branch 1 taken 2834468 times.
4372047 if(current_item(itype_map))
2250 {
2251 2834468 int32_t itemid =
2252
2/2
✓ Branch 0 taken 2823834 times.
✓ Branch 1 taken 10634 times.
2834468 get_qr(qr_HARDCODED_LITEM_LTMS)
2253 ? iMap
2254 10634 : getHighestLevelEvenUnowned(itemsbuf, itype_map);
2255
2/4
✓ Branch 0 taken 2834468 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2834468 times.
2834468 if(itemid > -1 && checkbunny(itemid))
2256 2834468 tile+=itemsbuf[itemid].ltm;
2257 2834468 }
2258
2259
2/2
✓ Branch 0 taken 2060058 times.
✓ Branch 1 taken 2311989 times.
4372047 if(current_item(itype_compass))
2260 {
2261 2311989 int32_t itemid =
2262
2/2
✓ Branch 0 taken 2295941 times.
✓ Branch 1 taken 16048 times.
2311989 get_qr(qr_HARDCODED_LITEM_LTMS)
2263 ? iCompass
2264 16048 : getHighestLevelEvenUnowned(itemsbuf, itype_compass);
2265
2/4
✓ Branch 0 taken 2311989 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2311989 times.
2311989 if(itemid > -1 && checkbunny(itemid))
2266 2311989 tile+=itemsbuf[itemid].ltm;
2267 2311989 }
2268
2269
2/2
✓ Branch 0 taken 1285631 times.
✓ Branch 1 taken 3086416 times.
4372047 if(current_item(itype_bosskey))
2270 {
2271 3086416 int32_t itemid =
2272
2/2
✓ Branch 0 taken 2993139 times.
✓ Branch 1 taken 93277 times.
3086416 get_qr(qr_HARDCODED_LITEM_LTMS)
2273 ? iBossKey
2274 93277 : getHighestLevelEvenUnowned(itemsbuf, itype_bosskey);
2275
2/4
✓ Branch 0 taken 3086416 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3086416 times.
3086416 if(itemid > -1 && checkbunny(itemid))
2276 3086416 tile+=itemsbuf[itemid].ltm;
2277 3086416 }
2278
2279
2/2
✓ Branch 0 taken 48193 times.
✓ Branch 1 taken 4323854 times.
4372047 if(current_item(itype_magiccontainer))
2280 {
2281 4323854 int32_t itemid =
2282
2/2
✓ Branch 0 taken 3893055 times.
✓ Branch 1 taken 430799 times.
4323854 get_qr(qr_HARDCODED_LITEM_LTMS)
2283 ? iMagicC
2284 430799 : getHighestLevelEvenUnowned(itemsbuf, itype_magiccontainer);
2285
3/4
✓ Branch 0 taken 4323854 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
✓ Branch 3 taken 4323837 times.
4323854 if(itemid > -1 && checkbunny(itemid))
2286 4323837 tile+=itemsbuf[itemid].ltm;
2287 4323854 }
2288
2289
2/2
✓ Branch 0 taken 1302861 times.
✓ Branch 1 taken 3069186 times.
4372047 if(current_item(itype_triforcepiece))
2290 {
2291 3069186 int32_t itemid =
2292
1/2
✓ Branch 0 taken 3069186 times.
✗ Branch 1 not taken.
3069186 get_qr(qr_HARDCODED_LITEM_LTMS)
2293 ? iTriforce
2294 : getHighestLevelEvenUnowned(itemsbuf, itype_triforcepiece);
2295
2/4
✓ Branch 0 taken 3069186 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3069186 times.
3069186 if(itemid > -1 && checkbunny(itemid))
2296 3069186 tile+=itemsbuf[itemid].ltm;
2297 3069186 }
2298
2299
2/2
✓ Branch 0 taken 2238488064 times.
✓ Branch 1 taken 4372047 times.
2242860111 for(int32_t i=0; i<itype_max; i++)
2300 {
2301
2/2
✓ Branch 0 taken 2017846784 times.
✓ Branch 1 taken 220641280 times.
2238488064 if(!get_qr(qr_HARDCODED_LITEM_LTMS))
2302 {
2303
2/2
✓ Branch 0 taken 4309400 times.
✓ Branch 1 taken 216331880 times.
220641280 switch(i)
2304 {
2305 case itype_bomb:
2306 case itype_sbomb:
2307 case itype_clock:
2308 case itype_key:
2309 case itype_lkey:
2310 case itype_map:
2311 case itype_compass:
2312 case itype_bosskey:
2313 case itype_magiccontainer:
2314 case itype_triforcepiece:
2315 4309400 continue; //already handled
2316 }
2317 216331880 }
2318 2234178664 int32_t itemid = current_item_id(i,false);
2319
2/2
✓ Branch 0 taken 2229806617 times.
✓ Branch 1 taken 4372047 times.
2234178664 if(i == itype_shield)
2320 4372047 itemid = getCurrentShield(false);
2321
2322
4/4
✓ Branch 0 taken 114055073 times.
✓ Branch 1 taken 2120123591 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 114055072 times.
2234178664 if(itemid < 0 || !checkbunny(itemid))
2323 2120123592 continue;
2324
2325 114055072 itemdata const& itm = itemsbuf[itemid];
2326
2327
2/2
✓ Branch 0 taken 110392519 times.
✓ Branch 1 taken 3662553 times.
114055072 switch(itm.family)
2328 {
2329 case itype_shield:
2330
1/2
✓ Branch 0 taken 3662553 times.
✗ Branch 1 not taken.
3662553 if(itm.flags & item_flag9) //active shield
2331 {
2332 if(!usingActiveShield(itemid))
2333 {
2334 tile+=itm.misc6; //'Inactive PTM'
2335 continue;
2336 }
2337 }
2338 3662553 break;
2339 }
2340
2341 114055072 tile+=itm.ltm;
2342 114055072 }
2343
2344 4372047 tilemod_cache_value = tile;
2345 4372047 tilemod_cache_state = state;
2346 4372047 return tile;
2347 12764472 }
2348
2349 12764472 int32_t bunny_tile_mod()
2350 {
2351
2/2
✓ Branch 0 taken 1870 times.
✓ Branch 1 taken 12762602 times.
12764472 if(Hero.BunnyClock())
2352 {
2353 1870 return game->get_bunny_ltm();
2354 }
2355 12762602 return 0;
2356 12764472 }
2357
2358 // Hints are drawn on a separate layer to combo reveals.
2359 20010 void draw_lens_under(BITMAP *dest, bool layer)
2360 {
2361 //Lens flag 1: Replacement for qr_LENSHINTS; if set, lens will show hints. Does nothing if flag 2 is set.
2362 //Lens flag 2: Disable "hints", prevent rendering of Secret Combos
2363 //Lens flag 3: Don't show armos/chest/dive items
2364 //Lens flag 4: Show Raft Paths
2365 //Lens flag 5: Show Invisible Enemies
2366
4/4
✓ Branch 0 taken 456 times.
✓ Branch 1 taken 19554 times.
✓ Branch 2 taken 9777 times.
✓ Branch 3 taken 9777 times.
20010 bool hints = (itemsbuf[Hero.getLastLensID()].flags & item_flag2) ? false : (layer && (itemsbuf[Hero.getLastLensID()].flags & item_flag1));
2367
2368 20010 int32_t strike_hint_table[11]=
2369 {
2370 mfARROW, mfBOMB, mfBRANG, mfWANDMAGIC,
2371 mfSWORD, mfREFMAGIC, mfHOOKSHOT,
2372 mfREFFIREBALL, mfHAMMER, mfSWORDBEAM, mfWAND
2373 };
2374
2375 {
2376 20010 int32_t blink_rate=flash_reduction_enabled()?6:1;
2377 20010 int32_t tempitem, tempweapon=0;
2378 20010 strike_hint=strike_hint_table[strike_hint_counter];
2379
2380
2/2
✓ Branch 0 taken 19412 times.
✓ Branch 1 taken 598 times.
20010 if(strike_hint_timer>32)
2381 {
2382 598 strike_hint_timer=0;
2383 598 strike_hint_counter=((strike_hint_counter+1)%11);
2384 598 }
2385
2386 20010 ++strike_hint_timer;
2387
2388
2/2
✓ Branch 0 taken 3521760 times.
✓ Branch 1 taken 20010 times.
3541770 for(int32_t i=0; i<176; i++)
2389 {
2390 3521760 int32_t x = (i & 15) << 4;
2391 3521760 int32_t y = (i & 0xF0) + playing_field_offset;
2392 3521760 int32_t tempitemx=-16, tempitemy=-16;
2393 3521760 int32_t tempweaponx=-16, tempweapony=-16;
2394
2395
2/2
✓ Branch 0 taken 7043520 times.
✓ Branch 1 taken 3521760 times.
10565280 for(int32_t iter=0; iter<2; ++iter)
2396 {
2397 7043520 int32_t checkflag=0;
2398
2399
2/2
✓ Branch 0 taken 3521760 times.
✓ Branch 1 taken 3521760 times.
7043520 if(iter==0)
2400 {
2401 3521760 checkflag=combobuf[tmpscr->data[i]].flag;
2402 3521760 }
2403 else
2404 {
2405 3521760 checkflag=tmpscr->sflag[i];
2406 }
2407
2408
2/2
✓ Branch 0 taken 7042422 times.
✓ Branch 1 taken 1098 times.
7043520 if(checkflag==mfSTRIKE)
2409 {
2410
2/2
✓ Branch 0 taken 192 times.
✓ Branch 1 taken 906 times.
1098 if(!hints)
2411 {
2412
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 906 times.
906 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sSTRIKE],tmpscr->secretcset[sSTRIKE]);
2413 906 }
2414 else
2415 {
2416 192 checkflag = strike_hint;
2417 }
2418 1098 }
2419
2420
21/36
✓ Branch 0 taken 6894870 times.
✓ Branch 1 taken 3258 times.
✓ Branch 2 taken 108898 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2602 times.
✓ Branch 5 taken 28750 times.
✓ Branch 6 taken 2418 times.
✓ Branch 7 taken 504 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 814 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 93 times.
✓ Branch 15 taken 96 times.
✓ Branch 16 taken 24 times.
✓ Branch 17 taken 25 times.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✓ Branch 20 taken 138 times.
✓ Branch 21 taken 16 times.
✓ Branch 22 taken 16 times.
✓ Branch 23 taken 7 times.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✓ Branch 27 taken 16 times.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✓ Branch 31 taken 17 times.
✓ Branch 32 taken 35 times.
✓ Branch 33 taken 17 times.
✗ Branch 34 not taken.
✓ Branch 35 taken 906 times.
7043520 switch(checkflag)
2421 {
2422 case 0:
2423 case mfZELDA:
2424 case mfPUSHED:
2425 case mfENEMY0:
2426 case mfENEMY1:
2427 case mfENEMY2:
2428 case mfENEMY3:
2429 case mfENEMY4:
2430 case mfENEMY5:
2431 case mfENEMY6:
2432 case mfENEMY7:
2433 case mfENEMY8:
2434 case mfENEMY9:
2435 case mfSINGLE:
2436 case mfSINGLE16:
2437 case mfNOENEMY:
2438 case mfTRAP_H:
2439 case mfTRAP_V:
2440 case mfTRAP_4:
2441 case mfTRAP_LR:
2442 case mfTRAP_UD:
2443 case mfNOGROUNDENEMY:
2444 case mfNOBLOCKS:
2445 case mfSCRIPT1:
2446 case mfSCRIPT2:
2447 case mfSCRIPT3:
2448 case mfSCRIPT4:
2449 case mfSCRIPT5:
2450 case mfSCRIPT6:
2451 case mfSCRIPT7:
2452 case mfSCRIPT8:
2453 case mfSCRIPT9:
2454 case mfSCRIPT10:
2455 case mfSCRIPT11:
2456 case mfSCRIPT12:
2457 case mfSCRIPT13:
2458 case mfSCRIPT14:
2459 case mfSCRIPT15:
2460 case mfSCRIPT16:
2461 case mfSCRIPT17:
2462 case mfSCRIPT18:
2463 case mfSCRIPT19:
2464 case mfSCRIPT20:
2465 case mfPITHOLE:
2466 case mfPITFALLFLOOR:
2467 case mfLAVA:
2468 case mfICE:
2469 case mfICEDAMAGE:
2470 case mfDAMAGE1:
2471 case mfDAMAGE2:
2472 case mfDAMAGE4:
2473 case mfDAMAGE8:
2474 case mfDAMAGE16:
2475 case mfDAMAGE32:
2476 case mfFREEZEALL:
2477 case mfFREZEALLANSFFCS:
2478 case mfFREEZEFFCSOLY:
2479 case mfSCRITPTW1TRIG:
2480 case mfSCRITPTW2TRIG:
2481 case mfSCRITPTW3TRIG:
2482 case mfSCRITPTW4TRIG:
2483 case mfSCRITPTW5TRIG:
2484 case mfSCRITPTW6TRIG:
2485 case mfSCRITPTW7TRIG:
2486 case mfSCRITPTW8TRIG:
2487 case mfSCRITPTW9TRIG:
2488 case mfSCRITPTW10TRIG:
2489 case mfTROWEL:
2490 case mfTROWELNEXT:
2491 case mfTROWELSPECIALITEM:
2492 case mfSLASHPOT:
2493 case mfLIFTPOT:
2494 case mfLIFTORSLASH:
2495 case mfLIFTROCK:
2496 case mfLIFTROCKHEAVY:
2497 case mfDROPITEM:
2498 case mfSPECIALITEM:
2499 case mfDROPKEY:
2500 case mfDROPLKEY:
2501 case mfDROPCOMPASS:
2502 case mfDROPMAP:
2503 case mfDROPBOSSKEY:
2504 case mfSPAWNNPC:
2505 case mfSWITCHHOOK:
2506 case mfSIDEVIEWLADDER:
2507 case mfSIDEVIEWPLATFORM:
2508 case mfNOENEMYSPAWN:
2509 case mfENEMYALL:
2510 case mfNOMIRROR:
2511 case mfUNSAFEGROUND:
2512 case mf168:
2513 case mf169:
2514 case mf170:
2515 case mf171:
2516 case mf172:
2517 case mf173:
2518 case mf174:
2519 case mf175:
2520 case mf176:
2521 case mf177:
2522 case mf178:
2523 case mf179:
2524 case mf180:
2525 case mf181:
2526 case mf182:
2527 case mf183:
2528 case mf184:
2529 case mf185:
2530 case mf186:
2531 case mf187:
2532 case mf188:
2533 case mf189:
2534 case mf190:
2535 case mf191:
2536 case mf192:
2537 case mf193:
2538 case mf194:
2539 case mf195:
2540 case mf196:
2541 case mf197:
2542 case mf198:
2543 case mf199:
2544 case mf200:
2545 case mf201:
2546 case mf202:
2547 case mf203:
2548 case mf204:
2549 case mf205:
2550 case mf206:
2551 case mf207:
2552 case mf208:
2553 case mf209:
2554 case mf210:
2555 case mf211:
2556 case mf212:
2557 case mf213:
2558 case mf214:
2559 case mf215:
2560 case mf216:
2561 case mf217:
2562 case mf218:
2563 case mf219:
2564 case mf220:
2565 case mf221:
2566 case mf222:
2567 case mf223:
2568 case mf224:
2569 case mf225:
2570 case mf226:
2571 case mf227:
2572 case mf228:
2573 case mf229:
2574 case mf230:
2575 case mf231:
2576 case mf232:
2577 case mf233:
2578 case mf234:
2579 case mf235:
2580 case mf236:
2581 case mf237:
2582 case mf238:
2583 case mf239:
2584 case mf240:
2585 case mf241:
2586 case mf242:
2587 case mf243:
2588 case mf244:
2589 case mf245:
2590 case mf246:
2591 case mf247:
2592 case mf248:
2593 case mf249:
2594 case mf250:
2595 case mf251:
2596 case mf252:
2597 case mf253:
2598 case mf254:
2599 case mfEXTENDED:
2600 6894870 break;
2601
2602 case mfPUSHUD:
2603 case mfPUSHLR:
2604 case mfPUSH4:
2605 case mfPUSHU:
2606 case mfPUSHD:
2607 case mfPUSHL:
2608 case mfPUSHR:
2609 case mfPUSHUDNS:
2610 case mfPUSHLRNS:
2611 case mfPUSH4NS:
2612 case mfPUSHUNS:
2613 case mfPUSHDNS:
2614 case mfPUSHLNS:
2615 case mfPUSHRNS:
2616 case mfPUSHUDINS:
2617 case mfPUSHLRINS:
2618 case mfPUSH4INS:
2619 case mfPUSHUINS:
2620 case mfPUSHDINS:
2621 case mfPUSHLINS:
2622 case mfPUSHRINS:
2623
3/4
✓ Branch 0 taken 1939 times.
✓ Branch 1 taken 1319 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1939 times.
3258 if(!hints && ((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&16))
2624
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 1939 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1939 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
1939 || ((get_debug() && zc_getkey(KEY_N)) && (frame&16))))
2625 {
2626 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->undercombo,tmpscr->undercset);
2627 }
2628
2629
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3258 times.
3258 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2630
3/6
✓ Branch 0 taken 2520 times.
✓ Branch 1 taken 738 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 738 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
3258 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2631 {
2632
2/2
✓ Branch 0 taken 1488 times.
✓ Branch 1 taken 1032 times.
2520 if(hints)
2633 {
2634
3/3
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 63 times.
✓ Branch 2 taken 897 times.
1032 switch(combobuf[tmpscr->data[i]].type)
2635 {
2636 case cPUSH_HEAVY:
2637 case cPUSH_HW:
2638 72 tempitem=getItemIDPower(itemsbuf,itype_bracelet,1);
2639 72 tempitemx=x, tempitemy=y;
2640
2641
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
72 if(tempitem>-1)
2642 72 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2643
2644 72 break;
2645
2646 case cPUSH_HEAVY2:
2647 case cPUSH_HW2:
2648 63 tempitem=getItemIDPower(itemsbuf,itype_bracelet,2);
2649 63 tempitemx=x, tempitemy=y;
2650
2651
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 63 times.
63 if(tempitem>-1)
2652 63 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2653
2654 63 break;
2655 }
2656 1032 }
2657 2520 }
2658
2659 3258 break;
2660
2661 case mfWHISTLE:
2662
1/2
✓ Branch 0 taken 2418 times.
✗ Branch 1 not taken.
2418 if(hints)
2663 {
2664 tempitem=getItemID(itemsbuf,itype_whistle,1);
2665
2666 if(tempitem<0) break;
2667
2668 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2669 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2670 {
2671 tempitemx=x;
2672 tempitemy=y;
2673 }
2674
2675 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2676 }
2677
2678 2418 break;
2679
2680 //Why is this here?
2681 case mfFAIRY:
2682 case mfMAGICFAIRY:
2683 case mfALLFAIRY:
2684 if(hints)
2685 {
2686 tempitem=getItemID(itemsbuf, itype_fairy,1);//iFairyMoving;
2687
2688 if(tempitem < 0) break;
2689
2690 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2691 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2692 {
2693 tempitemx=x;
2694 tempitemy=y;
2695 }
2696
2697 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2698 }
2699
2700 break;
2701
2702 case mfANYFIRE:
2703
2/2
✓ Branch 0 taken 252 times.
✓ Branch 1 taken 252 times.
504 if(!hints)
2704 {
2705
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 252 times.
252 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sBCANDLE],tmpscr->secretcset[sBCANDLE]);
2706 252 }
2707 else
2708 {
2709 252 tempitem=getItemID(itemsbuf,itype_candle,1);
2710
2711
1/2
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
252 if(tempitem<0) break;
2712
2713
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 252 times.
252 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2714
3/6
✓ Branch 0 taken 189 times.
✓ Branch 1 taken 63 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 63 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
252 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2715 {
2716 189 tempitemx=x;
2717 189 tempitemy=y;
2718 189 }
2719
2720 252 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2721 }
2722
2723 504 break;
2724
2725 case mfSTRONGFIRE:
2726 if(!hints)
2727 {
2728 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sRCANDLE],tmpscr->secretcset[sRCANDLE]);
2729 }
2730 else
2731 {
2732 tempitem=getItemID(itemsbuf,itype_candle,2);
2733
2734 if(tempitem<0) break;
2735
2736 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2737 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2738 {
2739 tempitemx=x;
2740 tempitemy=y;
2741 }
2742
2743 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2744 }
2745
2746 break;
2747
2748 case mfMAGICFIRE:
2749 if(!hints)
2750 {
2751 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sWANDFIRE],tmpscr->secretcset[sWANDFIRE]);
2752 }
2753 else
2754 {
2755 tempitem=getItemID(itemsbuf,itype_wand,1);
2756
2757 if(tempitem<0) break;
2758
2759 tempweapon=wFire;
2760
2761 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2762 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2763 {
2764 tempitemx=x;
2765 tempitemy=y;
2766 }
2767 else
2768 {
2769 tempweaponx=x;
2770 tempweapony=y;
2771 }
2772
2773 putweapon(dest,tempweaponx,tempweapony,tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
2774 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2775 }
2776
2777 break;
2778
2779 case mfDIVINEFIRE:
2780 if(!hints)
2781 {
2782 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sDIVINEFIRE],tmpscr->secretcset[sDIVINEFIRE]);
2783 }
2784 else
2785 {
2786 tempitem=getItemID(itemsbuf,itype_divinefire,1);
2787
2788 if(tempitem<0) break;
2789
2790 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2791 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2792 {
2793 tempitemx=x;
2794 tempitemy=y;
2795 }
2796
2797 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2798 }
2799
2800 break;
2801
2802 case mfARROW:
2803
2/2
✓ Branch 0 taken 82 times.
✓ Branch 1 taken 732 times.
814 if(!hints)
2804 {
2805
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 732 times.
732 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sARROW],tmpscr->secretcset[sARROW]);
2806 732 }
2807 else
2808 {
2809 82 tempitem=getItemID(itemsbuf,itype_arrow,1);
2810
2811
1/2
✓ Branch 0 taken 82 times.
✗ Branch 1 not taken.
82 if(tempitem<0) break;
2812
2813
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 82 times.
82 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2814
3/6
✓ Branch 0 taken 61 times.
✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 21 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
82 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2815 {
2816 61 tempitemx=x;
2817 61 tempitemy=y;
2818 61 }
2819
2820 82 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2821 }
2822
2823 814 break;
2824
2825 case mfSARROW:
2826 if(!hints)
2827 {
2828 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sSARROW],tmpscr->secretcset[sSARROW]);
2829 }
2830 else
2831 {
2832 tempitem=getItemID(itemsbuf,itype_arrow,2);
2833
2834 if(tempitem<0) break;
2835
2836 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2837 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2838 {
2839 tempitemx=x;
2840 tempitemy=y;
2841 }
2842
2843 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2844 }
2845
2846 break;
2847
2848 case mfGARROW:
2849 if(!hints)
2850 {
2851 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sGARROW],tmpscr->secretcset[sGARROW]);
2852 }
2853 else
2854 {
2855 tempitem=getItemID(itemsbuf,itype_arrow,3);
2856
2857 if(tempitem<0) break;
2858
2859 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2860 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2861 {
2862 tempitemx=x;
2863 tempitemy=y;
2864 }
2865
2866 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2867 }
2868
2869 break;
2870
2871 case mfBOMB:
2872
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 76 times.
93 if(!hints)
2873 {
2874
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 76 times.
76 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sBOMB],tmpscr->secretcset[sBOMB]);
2875 76 }
2876 else
2877 {
2878 //tempitem=getItemID(itemsbuf,itype_bomb,1);
2879 17 tempweapon = wLitBomb;
2880
2881 //if (tempitem<0) break;
2882
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2883
3/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
17 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2884 {
2885 12 tempweaponx=x;
2886 12 tempweapony=y;
2887 12 }
2888
2889 17 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
2890 }
2891
2892 93 break;
2893
2894 case mfSBOMB:
2895
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 48 times.
96 if(!hints)
2896 {
2897
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sSBOMB],tmpscr->secretcset[sSBOMB]);
2898 48 }
2899 else
2900 {
2901 //tempitem=getItemID(itemsbuf,itype_sbomb,1);
2902 //if (tempitem<0) break;
2903 48 tempweapon = wLitSBomb;
2904
2905
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2906
3/6
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
48 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2907 {
2908 36 tempweaponx=x;
2909 36 tempweapony=y;
2910 36 }
2911
2912 48 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
2913 }
2914
2915 96 break;
2916
2917 case mfARMOS_SECRET:
2918
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 12 times.
24 if(!hints)
2919 {
2920
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sSTAIRS],tmpscr->secretcset[sSTAIRS]);
2921 12 }
2922 24 break;
2923
2924 case mfBRANG:
2925
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 20 times.
25 if(!hints)
2926 {
2927
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sBRANG],tmpscr->secretcset[sBRANG]);
2928 20 }
2929 else
2930 {
2931 5 tempitem=getItemID(itemsbuf,itype_brang,1);
2932
2933
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if(tempitem<0) break;
2934
2935
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2936
3/6
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
5 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2937 {
2938 4 tempitemx=x;
2939 4 tempitemy=y;
2940 4 }
2941
2942 5 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2943 }
2944
2945 25 break;
2946
2947 case mfMBRANG:
2948 if(!hints)
2949 {
2950 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sMBRANG],tmpscr->secretcset[sMBRANG]);
2951 }
2952 else
2953 {
2954 tempitem=getItemID(itemsbuf,itype_brang,2);
2955
2956 if(tempitem<0) break;
2957
2958 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2959 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2960 {
2961 tempitemx=x;
2962 tempitemy=y;
2963 }
2964
2965 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2966 }
2967
2968 break;
2969
2970 case mfFBRANG:
2971 if(!hints)
2972 {
2973 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sFBRANG],tmpscr->secretcset[sFBRANG]);
2974 }
2975 else
2976 {
2977 tempitem=getItemID(itemsbuf,itype_brang,3);
2978
2979 if(tempitem<0) break;
2980
2981 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2982 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2983 {
2984 tempitemx=x;
2985 tempitemy=y;
2986 }
2987
2988 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2989 }
2990
2991 break;
2992
2993 case mfWANDMAGIC:
2994
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 138 times.
138 if(!hints)
2995 {
2996
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 138 times.
138 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sWANDMAGIC],tmpscr->secretcset[sWANDMAGIC]);
2997 138 }
2998 else
2999 {
3000 tempitem=getItemID(itemsbuf,itype_wand,1);
3001
3002 if(tempitem<0) break;
3003
3004 tempweapon=itemsbuf[tempitem].wpn3;
3005
3006 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3007 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3008 {
3009 tempitemx=x;
3010 tempitemy=y;
3011 }
3012 else
3013 {
3014 tempweaponx=x;
3015 tempweapony=y;
3016 --lens_hint_weapon[wMagic][4];
3017
3018 if(lens_hint_weapon[wMagic][4]<-8)
3019 {
3020 lens_hint_weapon[wMagic][4]=8;
3021 }
3022 }
3023
3024 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3025 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3026 }
3027
3028 138 break;
3029
3030 case mfREFMAGIC:
3031
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!hints)
3032 {
3033 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sREFMAGIC],tmpscr->secretcset[sREFMAGIC]);
3034 }
3035 else
3036 {
3037 16 tempitem=getItemID(itemsbuf,itype_shield,3);
3038
3039
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(tempitem<0) break;
3040
3041 16 tempweapon=ewMagic;
3042
3043
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3044
3/6
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
16 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3045 {
3046 13 tempitemx=x;
3047 13 tempitemy=y;
3048 13 }
3049 else
3050 {
3051 3 tempweaponx=x;
3052 3 tempweapony=y;
3053
3054
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 if(lens_hint_weapon[ewMagic][2]==up)
3055 {
3056 1 --lens_hint_weapon[ewMagic][4];
3057 1 }
3058 else
3059 {
3060 2 ++lens_hint_weapon[ewMagic][4];
3061 }
3062
3063
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(lens_hint_weapon[ewMagic][4]>8)
3064 {
3065 lens_hint_weapon[ewMagic][2]=up;
3066 }
3067
3068
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 if(lens_hint_weapon[ewMagic][4]<=0)
3069 {
3070 2 lens_hint_weapon[ewMagic][2]=down;
3071 2 }
3072 }
3073
3074 16 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3075 16 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, lens_hint_weapon[ewMagic][2], lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3076 }
3077
3078 16 break;
3079
3080 case mfREFFIREBALL:
3081
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!hints)
3082 {
3083 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sREFFIREBALL],tmpscr->secretcset[sREFFIREBALL]);
3084 }
3085 else
3086 {
3087 16 tempitem=getItemID(itemsbuf,itype_shield,3);
3088
3089
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(tempitem<0) break;
3090
3091 16 tempweapon=ewFireball;
3092
3093
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3094
3/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
16 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3095 {
3096 12 tempitemx=x;
3097 12 tempitemy=y;
3098 12 tempweaponx=x;
3099 12 tempweapony=y;
3100 12 ++lens_hint_weapon[ewFireball][3];
3101
3102
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 1 times.
12 if(lens_hint_weapon[ewFireball][3]>8)
3103 {
3104 1 lens_hint_weapon[ewFireball][3]=-8;
3105 1 lens_hint_weapon[ewFireball][4]=8;
3106 1 }
3107
3108
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 4 times.
12 if(lens_hint_weapon[ewFireball][3]>0)
3109 {
3110 8 ++lens_hint_weapon[ewFireball][4];
3111 8 }
3112 else
3113 {
3114 4 --lens_hint_weapon[ewFireball][4];
3115 }
3116 12 }
3117
3118 16 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3119 16 putweapon(dest,tempweaponx+lens_hint_weapon[tempweapon][3],tempweapony+lens_hint_weapon[ewFireball][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3120 }
3121
3122 16 break;
3123
3124 case mfSWORD:
3125
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if(!hints)
3126 {
3127 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sSWORD],tmpscr->secretcset[sSWORD]);
3128 }
3129 else
3130 {
3131 7 tempitem=getItemID(itemsbuf,itype_sword,1);
3132
3133
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if(tempitem<0) break;
3134
3135
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3136
3/6
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
7 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3137 {
3138 5 tempitemx=x;
3139 5 tempitemy=y;
3140 5 }
3141
3142 7 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3143 }
3144
3145 7 break;
3146
3147 case mfWSWORD:
3148 if(!hints)
3149 {
3150 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sWSWORD],tmpscr->secretcset[sWSWORD]);
3151 }
3152 else
3153 {
3154 tempitem=getItemID(itemsbuf,itype_sword,2);
3155
3156 if(tempitem<0) break;
3157
3158 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3159 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3160 {
3161 tempitemx=x;
3162 tempitemy=y;
3163 }
3164
3165 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3166 }
3167
3168 break;
3169
3170 case mfMSWORD:
3171 if(!hints)
3172 {
3173 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sMSWORD],tmpscr->secretcset[sMSWORD]);
3174 }
3175 else
3176 {
3177 tempitem=getItemID(itemsbuf,itype_sword,3);
3178
3179 if(tempitem<0) break;
3180
3181 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3182 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3183 {
3184 tempitemx=x;
3185 tempitemy=y;
3186 }
3187
3188 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3189 }
3190
3191 break;
3192
3193 case mfXSWORD:
3194 if(!hints)
3195 {
3196 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sXSWORD],tmpscr->secretcset[sXSWORD]);
3197 }
3198 else
3199 {
3200 tempitem=getItemID(itemsbuf,itype_sword,4);
3201
3202 if(tempitem<0) break;
3203
3204 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3205 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3206 {
3207 tempitemx=x;
3208 tempitemy=y;
3209 }
3210
3211 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3212 }
3213
3214 break;
3215
3216 case mfSWORDBEAM:
3217
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!hints)
3218 {
3219 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sSWORDBEAM],tmpscr->secretcset[sSWORDBEAM]);
3220 }
3221 else
3222 {
3223 16 tempitem=getItemID(itemsbuf,itype_sword,1);
3224
3225
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(tempitem<0) break;
3226
3227
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3228
3/6
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
16 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3229 {
3230 11 tempitemx=x;
3231 11 tempitemy=y;
3232 11 }
3233
3234 16 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 1);
3235 }
3236
3237 16 break;
3238
3239 case mfWSWORDBEAM:
3240 if(!hints)
3241 {
3242 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sWSWORDBEAM],tmpscr->secretcset[sWSWORDBEAM]);
3243 }
3244 else
3245 {
3246 tempitem=getItemID(itemsbuf,itype_sword,2);
3247
3248 if(tempitem<0) break;
3249
3250 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3251 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3252 {
3253 tempitemx=x;
3254 tempitemy=y;
3255 }
3256
3257 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 2);
3258 }
3259
3260 break;
3261
3262 case mfMSWORDBEAM:
3263 if(!hints)
3264 {
3265 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sMSWORDBEAM],tmpscr->secretcset[sMSWORDBEAM]);
3266 }
3267 else
3268 {
3269 tempitem=getItemID(itemsbuf,itype_sword,3);
3270
3271 if(tempitem<0) break;
3272
3273 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3274 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3275 {
3276 tempitemx=x;
3277 tempitemy=y;
3278 }
3279
3280 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 3);
3281 }
3282
3283 break;
3284
3285 case mfXSWORDBEAM:
3286 if(!hints)
3287 {
3288 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sXSWORDBEAM],tmpscr->secretcset[sXSWORDBEAM]);
3289 }
3290 else
3291 {
3292 tempitem=getItemID(itemsbuf,itype_sword,4);
3293
3294 if(tempitem<0) break;
3295
3296 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3297 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3298 {
3299 tempitemx=x;
3300 tempitemy=y;
3301 }
3302
3303 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 4);
3304 }
3305
3306 break;
3307
3308 case mfHOOKSHOT:
3309
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(!hints)
3310 {
3311 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sHOOKSHOT],tmpscr->secretcset[sHOOKSHOT]);
3312 }
3313 else
3314 {
3315 17 tempitem=getItemID(itemsbuf,itype_hookshot,1);
3316
3317
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(tempitem<0) break;
3318
3319
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3320
3/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
17 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3321 {
3322 12 tempitemx=x;
3323 12 tempitemy=y;
3324 12 }
3325
3326 17 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3327 }
3328
3329 17 break;
3330
3331 case mfWAND:
3332
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 if(!hints)
3333 {
3334 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sWAND],tmpscr->secretcset[sWAND]);
3335 }
3336 else
3337 {
3338 35 tempitem=getItemID(itemsbuf,itype_wand,1);
3339
3340
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 if(tempitem<0) break;
3341
3342
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
35 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3343
3/6
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 7 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
35 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3344 {
3345 28 tempitemx=x;
3346 28 tempitemy=y;
3347 28 }
3348
3349 35 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3350 }
3351
3352 35 break;
3353
3354 case mfHAMMER:
3355
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(!hints)
3356 {
3357 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sHAMMER],tmpscr->secretcset[sHAMMER]);
3358 }
3359 else
3360 {
3361 17 tempitem=getItemID(itemsbuf,itype_hammer,1);
3362
3363
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(tempitem<0) break;
3364
3365
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3366
3/6
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
17 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3367 {
3368 13 tempitemx=x;
3369 13 tempitemy=y;
3370 13 }
3371
3372 17 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3373 }
3374
3375 17 break;
3376
3377 case mfARMOS_ITEM:
3378 case mfDIVE_ITEM:
3379
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2602 times.
✓ Branch 2 taken 2602 times.
✗ Branch 3 not taken.
2602 if((!getmapflag() || (tmpscr->flags9&fBELOWRETURN)) && !(itemsbuf[Hero.getLastLensID()].flags & item_flag3))
3380 {
3381 2602 putitem2(dest,x,y,tmpscr->catchall, lens_hint_item[tmpscr->catchall][0], lens_hint_item[tmpscr->catchall][1], 0);
3382 2602 }
3383 2602 break;
3384
3385 case 16:
3386 case 17:
3387 case 18:
3388 case 19:
3389 case 20:
3390 case 21:
3391 case 22:
3392 case 23:
3393 case 24:
3394 case 25:
3395 case 26:
3396 case 27:
3397 case 28:
3398 case 29:
3399 case 30:
3400 case 31:
3401
2/2
✓ Branch 0 taken 1008 times.
✓ Branch 1 taken 107890 times.
108898 if(!hints)
3402
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 107890 times.
215780 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
3403 107890 putcombo(dest,x,y,tmpscr->secretcombo[checkflag-16+4],tmpscr->secretcset[checkflag-16+4]);
3404
3405 108898 break;
3406 case mfSECRETSNEXT:
3407 if(!hints)
3408 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
3409 putcombo(dest,x,y,tmpscr->data[i]+1,tmpscr->cset[i]);
3410
3411 break;
3412
3413 case mfSTRIKE:
3414
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 906 times.
906 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
3415 {
3416 906 goto special;
3417 }
3418 else
3419 {
3420 break;
3421 }
3422
3423 28750 default: goto special;
3424
3425 special:
3426
8/8
✓ Branch 0 taken 14732 times.
✓ Branch 1 taken 14924 times.
✓ Branch 2 taken 528 times.
✓ Branch 3 taken 14204 times.
✓ Branch 4 taken 496 times.
✓ Branch 5 taken 32 times.
✓ Branch 6 taken 6108 times.
✓ Branch 7 taken 8128 times.
29656 if(layer && ((checkflag!=mfRAFT && checkflag!=mfRAFT_BRANCH&& checkflag!=mfRAFT_BOUNCE) ||(itemsbuf[Hero.getLastLensID()].flags & item_flag4)))
3427 {
3428
4/8
✗ Branch 0 not taken.
✓ Branch 1 taken 6604 times.
✓ Branch 2 taken 4954 times.
✓ Branch 3 taken 1650 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1650 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
6604 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate)) || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3429 {
3430 4954 rectfill(dest,x,y,x+15,y+15,WHITE);
3431 4954 }
3432 6604 }
3433
3434 29656 break;
3435 }
3436 7043520 }
3437 3521760 }
3438
3439
2/2
✓ Branch 0 taken 10005 times.
✓ Branch 1 taken 10005 times.
20010 if(layer)
3440 {
3441
2/2
✓ Branch 0 taken 9646 times.
✓ Branch 1 taken 359 times.
10005 if(tmpscr->door[0]==dWALK)
3442 359 rectfill(dest, 120, 16+playing_field_offset, 135, 31+playing_field_offset, WHITE);
3443
3444
2/2
✓ Branch 0 taken 9582 times.
✓ Branch 1 taken 423 times.
10005 if(tmpscr->door[1]==dWALK)
3445 423 rectfill(dest, 120, 144+playing_field_offset, 135, 159+playing_field_offset, WHITE);
3446
3447
2/2
✓ Branch 0 taken 9423 times.
✓ Branch 1 taken 582 times.
10005 if(tmpscr->door[2]==dWALK)
3448 582 rectfill(dest, 16, 80+playing_field_offset, 31, 95+playing_field_offset, WHITE);
3449
3450
2/2
✓ Branch 0 taken 9381 times.
✓ Branch 1 taken 624 times.
10005 if(tmpscr->door[3]==dWALK)
3451 624 rectfill(dest, 224, 80+playing_field_offset, 239, 95+playing_field_offset, WHITE);
3452
3453
2/2
✓ Branch 0 taken 9962 times.
✓ Branch 1 taken 43 times.
10005 if(tmpscr->door[0]==dBOMB)
3454 {
3455 43 showbombeddoor(dest, 0);
3456 43 }
3457
3458
2/2
✓ Branch 0 taken 9966 times.
✓ Branch 1 taken 39 times.
10005 if(tmpscr->door[1]==dBOMB)
3459 {
3460 39 showbombeddoor(dest, 1);
3461 39 }
3462
3463
2/2
✓ Branch 0 taken 9999 times.
✓ Branch 1 taken 6 times.
10005 if(tmpscr->door[2]==dBOMB)
3464 {
3465 6 showbombeddoor(dest, 2);
3466 6 }
3467
3468
2/2
✓ Branch 0 taken 9968 times.
✓ Branch 1 taken 37 times.
10005 if(tmpscr->door[3]==dBOMB)
3469 {
3470 37 showbombeddoor(dest, 3);
3471 37 }
3472 10005 }
3473
3474
2/2
✓ Branch 0 taken 17976 times.
✓ Branch 1 taken 2034 times.
20010 if(tmpscr->stairx + tmpscr->stairy)
3475 {
3476
2/2
✓ Branch 0 taken 911 times.
✓ Branch 1 taken 1123 times.
2034 if(!hints)
3477 {
3478
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1123 times.
1123 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
3479 1123 putcombo(dest,tmpscr->stairx,tmpscr->stairy+playing_field_offset,tmpscr->secretcombo[sSTAIRS],tmpscr->secretcset[sSTAIRS]);
3480 1123 }
3481 else
3482 {
3483
2/2
✓ Branch 0 taken 863 times.
✓ Branch 1 taken 48 times.
911 if(tmpscr->flags&fWHISTLE)
3484 {
3485 48 tempitem=getItemID(itemsbuf,itype_whistle,1);
3486 48 int32_t tempitemx=-16;
3487 48 int32_t tempitemy=-16;
3488
3489
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&(blink_rate/4)))
3490
3/6
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 24 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
48 || ((get_debug() && zc_getkey(KEY_N)) && (frame&(blink_rate/4))))
3491 {
3492 24 tempitemx=tmpscr->stairx;
3493 24 tempitemy=tmpscr->stairy+playing_field_offset;
3494 24 }
3495
3496 48 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3497 48 }
3498 }
3499 2034 }
3500 }
3501 20010 }
3502
3503 BITMAP *lens_scr_d; // The "d" is for "destructible"!
3504
3505 9666 void draw_lens_over()
3506 {
3507 // Oh, what the heck.
3508 static BITMAP *lens_scr = NULL;
3509 static int32_t last_width = -1;
3510 9666 int32_t width = itemsbuf[current_item_id(itype_lens,true)].misc1;
3511
3512 // Only redraw the circle if the size has changed
3513
2/2
✓ Branch 0 taken 9647 times.
✓ Branch 1 taken 19 times.
9666 if(width != last_width)
3514 {
3515
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 2 times.
19 if(lens_scr == NULL)
3516 {
3517 17 lens_scr = create_bitmap_ex(8,2*288,2*(240-playing_field_offset));
3518 17 }
3519
3520 19 clear_to_color(lens_scr, BLACK);
3521 19 circlefill(lens_scr, 288, 240-playing_field_offset, width, 0);
3522 19 circle(lens_scr, 288, 240-playing_field_offset, width+2, 0);
3523 19 circle(lens_scr, 288, 240-playing_field_offset, width+5, 0);
3524 19 last_width=width;
3525 19 }
3526
3527 9666 masked_blit(lens_scr, framebuf, 288-(HeroX()+8), 240-playing_field_offset-(HeroY()+8), 0, playing_field_offset, 256, 168);
3528 9666 do_primitives(framebuf, SPLAYER_LENS_OVER, tmpscr, 0, playing_field_offset);
3529 9666 }
3530
3531 //----------------------------------------------------------------
3532
3533 31797 void draw_wavy(BITMAP *source, BITMAP *target, int32_t amplitude, bool interpol)
3534 {
3535 //recreating a big bitmap every frame is highly sluggish.
3536
4/6
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 31792 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
31797 static BITMAP *wavebuf = create_bitmap_ex(8,288,240-original_playing_field_offset);
3537 31797 clear_to_color(wavebuf, BLACK);
3538 31797 blit(source,wavebuf,0,original_playing_field_offset,16,0,256,224-original_playing_field_offset);
3539
3540 int32_t ofs;
3541
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 31797 times.
31797 amplitude = zc_min(2048,amplitude); // some arbitrary limit to prevent crashing
3542
4/6
✓ Branch 0 taken 31797 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 31797 times.
✓ Branch 4 taken 494 times.
✓ Branch 5 taken 31303 times.
31797 if(flash_reduction_enabled() && !get_qr(qr_WAVY_NO_EPILEPSY)) amplitude = zc_min(16,amplitude);
3543 31797 int32_t amp2=168;
3544
2/4
✓ Branch 0 taken 31797 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 31797 times.
31797 if(flash_reduction_enabled() && !get_qr(qr_WAVY_NO_EPILEPSY_2)) amp2*=2;
3545 31797 int32_t i=frame%amp2;
3546
3547
2/2
✓ Branch 0 taken 5341896 times.
✓ Branch 1 taken 31797 times.
5373693 for(int32_t j=0; j<168; j++)
3548 {
3549
3/4
✓ Branch 0 taken 2670948 times.
✓ Branch 1 taken 2670948 times.
✓ Branch 2 taken 2670948 times.
✗ Branch 3 not taken.
5341896 if(j&1 && interpol)
3550 {
3551 // Add 288*2048 to ensure it's never negative. It'll get modded out.
3552 ofs=288*2048+int32_t(zc::math::Sin((double(i+j)*2*PI/amp2))*amplitude);
3553 }
3554 else
3555 {
3556 5341896 ofs=288*2048-int32_t(zc::math::Sin((double(i+j)*2*PI/amp2))*amplitude);
3557 }
3558
3559
1/2
✓ Branch 0 taken 5341896 times.
✗ Branch 1 not taken.
5341896 if(ofs)
3560 {
3561
2/2
✓ Branch 0 taken 1367525376 times.
✓ Branch 1 taken 5341896 times.
1372867272 for(int32_t k=0; k<256; k++)
3562 {
3563 1367525376 target->line[j+original_playing_field_offset][k]=wavebuf->line[j][(k+ofs+16)%288];
3564 1367525376 }
3565 5341896 }
3566 5341896 }
3567 31797 }
3568
3569 28224 void draw_fuzzy(int32_t fuzz)
3570 // draws from right half of scrollbuf to framebuf
3571 {
3572 int32_t firstx, firsty, xstep, ystep, i, y, dx, dy;
3573 byte *start, *si, *di;
3574
3575
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28224 times.
28224 if(fuzz<1)
3576 fuzz = 1;
3577
3578 28224 xstep = 128%fuzz;
3579
3580
2/2
✓ Branch 0 taken 5880 times.
✓ Branch 1 taken 22344 times.
28224 if(xstep > 0)
3581 22344 xstep = fuzz-xstep;
3582
3583 28224 ystep = 112%fuzz;
3584
3585
2/2
✓ Branch 0 taken 8232 times.
✓ Branch 1 taken 19992 times.
28224 if(ystep > 0)
3586 19992 ystep = fuzz-ystep;
3587
3588 28224 firsty = 1;
3589
3590
2/2
✓ Branch 0 taken 28224 times.
✓ Branch 1 taken 1018416 times.
1046640 for(y=0; y<224;)
3591 {
3592 1018416 start = &(scrollbuf->line[y][256]);
3593
3594
4/4
✓ Branch 0 taken 1004304 times.
✓ Branch 1 taken 6336288 times.
✓ Branch 2 taken 6322176 times.
✓ Branch 3 taken 1018416 times.
7340592 for(dy=0; dy<ystep && dy+y<224; dy++)
3595 {
3596 6322176 si = start;
3597 6322176 di = &(framebuf->line[y+dy][0]);
3598 6322176 i = xstep;
3599 6322176 firstx = 1;
3600
3601
2/2
✓ Branch 0 taken 1618477056 times.
✓ Branch 1 taken 6322176 times.
1624799232 for(dx=0; dx<256; dx++)
3602 {
3603 1618477056 *(di++) = *si;
3604
3605
2/2
✓ Branch 0 taken 1363746048 times.
✓ Branch 1 taken 254731008 times.
1618477056 if(++i >= fuzz)
3606 {
3607
2/2
✓ Branch 0 taken 248408832 times.
✓ Branch 1 taken 6322176 times.
254731008 if(!firstx)
3608 248408832 si += fuzz;
3609 else
3610 {
3611 6322176 si += fuzz-xstep;
3612 6322176 firstx = 0;
3613 }
3614
3615 254731008 i = 0;
3616 254731008 }
3617 1618477056 }
3618 6322176 }
3619
3620
2/2
✓ Branch 0 taken 990192 times.
✓ Branch 1 taken 28224 times.
1018416 if(!firsty)
3621 990192 y += fuzz;
3622 else
3623 {
3624 28224 y += ystep;
3625 28224 ystep = fuzz;
3626 28224 firsty = 0;
3627 }
3628 }
3629 28224 }
3630
3631 18304952 void updatescr(bool allowwavy)
3632 {
3633
4/6
✓ Branch 0 taken 239 times.
✓ Branch 1 taken 18304713 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 239 times.
✓ Branch 4 taken 239 times.
✗ Branch 5 not taken.
18304952 static BITMAP *wavybuf = create_bitmap_ex(8,256,224);
3634
4/6
✓ Branch 0 taken 239 times.
✓ Branch 1 taken 18304713 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 239 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 239 times.
18304952 static BITMAP *panorama = create_bitmap_ex(8,256,224);
3635
3636
2/2
✓ Branch 0 taken 18277647 times.
✓ Branch 1 taken 27305 times.
18304952 if(toogam)
3637 {
3638 27305 textout_ex(framebuf,font,"no walls",8,216,1,-1);
3639 27305 }
3640
3641
1/2
✓ Branch 0 taken 18304952 times.
✗ Branch 1 not taken.
18304952 if(Showpal)
3642 dump_pal(framebuf);
3643
3644
2/2
✓ Branch 0 taken 17791928 times.
✓ Branch 1 taken 513024 times.
18304952 if(!Playing)
3645 513024 black_opening_count=0;
3646
3647
2/2
✓ Branch 0 taken 18142643 times.
✓ Branch 1 taken 162309 times.
18304952 if(black_opening_count<0) //shape is opening up
3648 {
3649 162309 black_opening(framebuf,black_opening_x,black_opening_y,(66+black_opening_count),66);
3650
3651
2/4
✓ Branch 0 taken 162309 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 162309 times.
162309 if(Advance||(!Paused))
3652 {
3653 162309 ++black_opening_count;
3654 162309 }
3655 162309 }
3656
2/2
✓ Branch 0 taken 18094661 times.
✓ Branch 1 taken 47982 times.
18142643 else if(black_opening_count>0) //shape is closing
3657 {
3658 47982 black_opening(framebuf,black_opening_x,black_opening_y,black_opening_count,66);
3659
3660
2/4
✓ Branch 0 taken 47982 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 47982 times.
47982 if(Advance||(!Paused))
3661 {
3662 47982 --black_opening_count;
3663 47982 }
3664 47982 }
3665
3666
3/4
✓ Branch 0 taken 18097847 times.
✓ Branch 1 taken 207105 times.
✓ Branch 2 taken 18097847 times.
✗ Branch 3 not taken.
18304952 if(black_opening_count==0&&black_opening_shape==bosFADEBLACK)
3667 {
3668 black_opening_shape = bosCIRCLE;
3669 memcpy(RAMpal, tempblackpal, PAL_SIZE*sizeof(RGB));
3670 refreshTints();
3671 refreshpal=true;
3672 }
3673
3674
2/2
✓ Branch 0 taken 17676213 times.
✓ Branch 1 taken 628739 times.
18304952 if(refreshpal)
3675 {
3676 628739 refreshpal=false;
3677 628739 RAMpal[253] = _RGB(0,0,0);
3678 628739 RAMpal[254] = _RGB(255,255,255);
3679 628739 hw_palette = &RAMpal;
3680 628739 update_hw_pal = true;
3681
3682 // Creating rgb_table and trans_table is pretty expensive, so try not to redo the same work
3683 // within a short period of time by using a cache.
3684 typedef std::array<uint32_t, PAL_SIZE> pal_table_cache_key;
3685 struct pal_table_cache_entry {
3686 RGB_MAP rgb_table;
3687 COLOR_MAP trans_table;
3688 };
3689
3/4
✓ Branch 0 taken 239 times.
✓ Branch 1 taken 628500 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 239 times.
628739 static std::map<pal_table_cache_key, pal_table_cache_entry> pal_table_cache;
3690
3691 static constexpr int pal_table_cache_max_memory_mb = 10;
3692 static constexpr int pal_table_cache_max_size = pal_table_cache_max_memory_mb / ((double)sizeof(pal_table_cache_entry) / 1024 / 1024);
3693
2/2
✓ Branch 0 taken 628574 times.
✓ Branch 1 taken 165 times.
628739 if (pal_table_cache.size() > pal_table_cache_max_size)
3694 165 pal_table_cache.clear();
3695
3696 pal_table_cache_key key;
3697
2/2
✓ Branch 0 taken 160957184 times.
✓ Branch 1 taken 628739 times.
161585923 for (int i = 0; i < PAL_SIZE; i++)
3698 160957184 key[i] = RAMpal[i].r + (RAMpal[i].g << 8) + (RAMpal[i].b << 16);
3699 628739 auto cache_it = pal_table_cache.find(key);
3700
2/2
✓ Branch 0 taken 24946 times.
✓ Branch 1 taken 603793 times.
628739 if (cache_it == pal_table_cache.end())
3701 {
3702 24946 create_rgb_table(&rgb_table, RAMpal, NULL);
3703 24946 create_zc_trans_table(&trans_table, RAMpal, 128, 128, 128);
3704 24946 pal_table_cache[key] = {rgb_table, trans_table};
3705 24946 trans_table2 = trans_table;
3706 24946 }
3707 else
3708 {
3709 603793 rgb_table = cache_it->second.rgb_table;
3710 603793 trans_table = cache_it->second.trans_table;
3711 603793 trans_table2 = cache_it->second.trans_table;
3712 }
3713
3714
2/2
✓ Branch 0 taken 160957184 times.
✓ Branch 1 taken 628739 times.
161585923 for(int32_t q=0; q<PAL_SIZE; q++)
3715 {
3716 160957184 trans_table2.data[0][q] = q;
3717 160957184 trans_table2.data[q][q] = q;
3718 160957184 }
3719 628739 }
3720
3721 18304952 bool clearwavy = (wavy <= 0);
3722
3723
2/2
✓ Branch 0 taken 8341 times.
✓ Branch 1 taken 18296611 times.
18304952 if(wavy <= 0)
3724 {
3725 // So far one thing can alter wavy apart from scripts: Wavy DMaps.
3726 18296611 wavy = (DMaps[currdmap].flags&dmfWAVY ? 4 : 0);
3727 18296611 }
3728
3729 18304952 blit(framebuf, wavybuf, 0, 0, 0, 0, 256, 224);
3730
3731
6/6
✓ Branch 0 taken 32047 times.
✓ Branch 1 taken 18272905 times.
✓ Branch 2 taken 31925 times.
✓ Branch 3 taken 122 times.
✓ Branch 4 taken 128 times.
✓ Branch 5 taken 31797 times.
18304952 if(wavy && Playing && allowwavy)
3732 {
3733 31797 draw_wavy(framebuf, wavybuf, wavy,false);
3734 31797 }
3735
3736
2/2
✓ Branch 0 taken 18296611 times.
✓ Branch 1 taken 8341 times.
18304952 if(clearwavy)
3737 18296611 wavy = 0; // Wavy was set by a DMap flag. Clear it.
3738
2/4
✓ Branch 0 taken 8341 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8341 times.
8341 else if(Playing && !Paused)
3739 8341 wavy--; // Wavy was set by a script. Decrement it.
3740
3741
5/6
✓ Branch 0 taken 17791928 times.
✓ Branch 1 taken 513024 times.
✓ Branch 2 taken 664395 times.
✓ Branch 3 taken 17127533 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 664395 times.
18304952 if(Playing && msgpos && !screenscrolling)
3742 {
3743
1/2
✓ Branch 0 taken 664395 times.
✗ Branch 1 not taken.
664395 if(!(msg_bg_display_buf->clip))
3744 664395 blit_msgstr_bg(framebuf,0,0,0,playing_field_offset,256,168);
3745
1/2
✓ Branch 0 taken 664395 times.
✗ Branch 1 not taken.
664395 if(!(msg_portrait_display_buf->clip))
3746 664395 blit_msgstr_prt(framebuf,0,0,0,playing_field_offset,256,168);
3747
1/2
✓ Branch 0 taken 664395 times.
✗ Branch 1 not taken.
664395 if(!(msg_txt_display_buf->clip))
3748 664395 blit_msgstr_fg(framebuf,0,0,0,playing_field_offset,256,168);
3749 664395 }
3750
3751
2/2
✓ Branch 0 taken 18118443 times.
✓ Branch 1 taken 186509 times.
18304952 bool nosubscr = (tmpscr->flags3&fNOSUBSCR && !(tmpscr->flags3&fNOSUBSCROFFSET));
3752
3753
2/2
✓ Branch 0 taken 18123716 times.
✓ Branch 1 taken 181236 times.
18304952 if(nosubscr)
3754 {
3755 181236 rectfill(panorama,0,0,255,passive_subscreen_height/2,0);
3756 181236 rectfill(panorama,0,168+passive_subscreen_height/2,255,168+passive_subscreen_height-1,0);
3757 181236 blit(wavybuf,panorama,0,playing_field_offset,0,passive_subscreen_height/2,256,224-passive_subscreen_height);
3758 181236 }
3759
3760 //TODO: Optimize blit 'overcalls' -Gleeok
3761
2/2
✓ Branch 0 taken 181236 times.
✓ Branch 1 taken 18123716 times.
18304952 BITMAP *source = nosubscr ? panorama : wavybuf;
3762 18304952 blit(source,framebuf,0,0,0,0,256,224);
3763
3764 18304952 update_hw_screen();
3765 18304952 }
3766
3767 //----------------------------------------------------------------
3768
3769 static PALETTE syspal;
3770 int32_t onGUISnapshot()
3771 {
3772 char buf[200];
3773 int32_t num=0;
3774 do
3775 {
3776 sprintf(buf, "%szc_screen%05d.%s", get_snap_str(), ++num, snapshotformat_str[SnapshotFormat][1]);
3777 }
3778 while(num<99999 && exists(buf));
3779
3780 if (!al_save_bitmap(buf, al_get_backbuffer(all_get_display())))
3781 InfoDialog("Error", "Failed to save snapshot").show();
3782
3783 return D_O_K;
3784 }
3785
3786 int32_t onNonGUISnapshot()
3787 {
3788 PALETTE temppal;
3789 get_palette(temppal);
3790 bool realpal=(zc_getkey(KEY_ZC_LCONTROL, true) || zc_getkey(KEY_ZC_RCONTROL, true));
3791
3792 char buf[200];
3793 int32_t num=0;
3794
3795 do
3796 {
3797 sprintf(buf, "%szc_screen%05d.%s", get_snap_str(), ++num, snapshotformat_str[SnapshotFormat][1]);
3798 }
3799 while(num<99999 && exists(buf));
3800
3801 if ((tmpscr->flags3&fNOSUBSCR && !(tmpscr->flags3&fNOSUBSCROFFSET)) && !(key[KEY_ALT]))
3802 {
3803 BITMAP *b = create_bitmap_ex(8,256,168);
3804 clear_to_color(b,0);
3805 blit(framebuf,b,0,passive_subscreen_height/2,0,0,256,168);
3806 alleg4_save_bitmap(b, SnapshotScale, buf, realpal ? temppal : RAMpal);
3807 destroy_bitmap(b);
3808 }
3809 else
3810 {
3811 alleg4_save_bitmap(framebuf, SnapshotScale, buf, realpal?temppal:RAMpal);
3812 }
3813
3814 return D_O_K;
3815 }
3816
3817 int32_t onSnapshot()
3818 {
3819 if(zc_getkey(KEY_LSHIFT, true)||zc_getkey(KEY_RSHIFT, true))
3820 {
3821 onGUISnapshot();
3822 }
3823 else
3824 {
3825 onNonGUISnapshot();
3826 }
3827
3828 return D_O_K;
3829 }
3830
3831 int32_t onSaveMapPic()
3832 {
3833 int32_t mapres2 = 0;
3834 char buf[200];
3835 int32_t num=0;
3836 mapscr tmpscr_b[2];
3837 mapscr tmpscr_c[6];
3838 BITMAP* _screen_draw_buffer = NULL;
3839 _screen_draw_buffer = create_bitmap_ex(8,256,224);
3840 set_clip_state(_screen_draw_buffer,1);
3841
3842 for(int32_t i=0; i<6; ++i)
3843 {
3844 tmpscr_c[i] = tmpscr2[i];
3845 tmpscr2[i].zero_memory();
3846
3847 if(i>=2)
3848 {
3849 continue;
3850 }
3851
3852 tmpscr_b[i] = tmpscr[i];
3853 tmpscr[i].zero_memory();
3854 }
3855
3856 do
3857 {
3858 sprintf(buf, "%szc_screen%05d.png", get_snap_str(), ++num);
3859 }
3860 while(num<99999 && exists(buf));
3861
3862 BITMAP* mappic = NULL;
3863
3864
3865 bool done=false, redraw=true;
3866
3867 mappic = create_bitmap_ex(8,(256*16)>>mapres,(176*8)>>mapres);
3868
3869 if(!mappic)
3870 {
3871 enter_sys_pal();
3872 jwin_alert("View Map","Not enough memory.",NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
3873 exit_sys_pal();
3874 return D_O_K;;
3875 }
3876
3877 // draw the map
3878 set_clip_rect(_screen_draw_buffer, 0, 0, _screen_draw_buffer->w, _screen_draw_buffer->h);
3879
3880 for(int32_t y=0; y<8; y++)
3881 {
3882 for(int32_t x=0; x<16; x++)
3883 {
3884 if(!displayOnMap(x, y))
3885 {
3886 rectfill(_screen_draw_buffer, 0, 0, 255, 223, WHITE);
3887 }
3888 else
3889 {
3890 int32_t s = (y<<4) + x;
3891 loadscr2(1,s,-1);
3892
3893 for(int32_t i=0; i<6; i++)
3894 {
3895 if(tmpscr[1].layermap[i]<=0)
3896 continue;
3897
3898 tmpscr2[i]=TheMaps[(tmpscr[1].layermap[i]-1)*MAPSCRS+tmpscr[1].layerscreen[i]];
3899 }
3900
3901 if(XOR((tmpscr+1)->flags7&fLAYER2BG, DMaps[currdmap].flags&dmfLAYER2BG)) do_layer(_screen_draw_buffer, 0, 2, tmpscr+1, -256, playing_field_offset, 2);
3902
3903 if(XOR((tmpscr+1)->flags7&fLAYER3BG, DMaps[currdmap].flags&dmfLAYER3BG)) do_layer(_screen_draw_buffer, 0, 3, tmpscr+1, -256, playing_field_offset, 2);
3904
3905 if(lenscheck(tmpscr+1,0)) putscr(_screen_draw_buffer,256,0,tmpscr+1);
3906 do_layer(_screen_draw_buffer, 0, 1, tmpscr+1, -256, playing_field_offset, 2);
3907
3908 if(!XOR((tmpscr+1)->flags7&fLAYER2BG, DMaps[currdmap].flags&dmfLAYER2BG)) do_layer(_screen_draw_buffer, 0, 2, tmpscr+1, -256, playing_field_offset, 2);
3909
3910 putscrdoors(_screen_draw_buffer,256,0,tmpscr+1);
3911 if(get_qr(qr_PUSHBLOCK_SPRITE_LAYER))
3912 {
3913 do_layer(_screen_draw_buffer, -2, 0, tmpscr+1, -256, playing_field_offset, 2);
3914 if(get_qr(qr_PUSHBLOCK_LAYER_1_2))
3915 {
3916 do_layer(_screen_draw_buffer, -2, 1, tmpscr+1, -256, playing_field_offset, 2);
3917 do_layer(_screen_draw_buffer, -2, 2, tmpscr+1, -256, playing_field_offset, 2);
3918 }
3919 }
3920 do_layer(_screen_draw_buffer, -3, 0, tmpscr+1, -256, playing_field_offset, 2); // Freeform combos!
3921
3922 if(!XOR((tmpscr+1)->flags7&fLAYER3BG, DMaps[currdmap].flags&dmfLAYER3BG)) do_layer(_screen_draw_buffer, 0, 3, tmpscr+1, -256, playing_field_offset, 2);
3923
3924 do_layer(_screen_draw_buffer, 0, 4, tmpscr+1, -256, playing_field_offset, 2);
3925 do_layer(_screen_draw_buffer, -1, 0, tmpscr+1, -256, playing_field_offset, 2);
3926 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3927 {
3928 do_layer(_screen_draw_buffer, -1, 1, tmpscr+1, -256, playing_field_offset, 2);
3929 do_layer(_screen_draw_buffer, -1, 2, tmpscr+1, -256, playing_field_offset, 2);
3930 }
3931 do_layer(_screen_draw_buffer, 0, 5, tmpscr+1, -256, playing_field_offset, 2);
3932 do_layer(_screen_draw_buffer, 0, 6, tmpscr+1, -256, playing_field_offset, 2);
3933
3934 }
3935
3936 stretch_blit(_screen_draw_buffer, mappic, 256, 0, 256, 176, x<<(8-mapres), (y*176)>>mapres, 256>>mapres, 176>>mapres);
3937 }
3938 }
3939
3940 for(int32_t i=0; i<6; ++i)
3941 {
3942 tmpscr2[i]=tmpscr_c[i];
3943
3944 if(i>=2)
3945 {
3946 continue;
3947 }
3948
3949 tmpscr[i]=tmpscr_b[i];
3950 }
3951
3952 save_bitmap(buf,mappic,RAMpal);
3953 destroy_bitmap(mappic);
3954 destroy_bitmap(_screen_draw_buffer);
3955 return D_O_K;
3956 }
3957
3958 55 void f_Quit(int32_t type)
3959 {
3960
2/4
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 55 times.
✗ Branch 3 not taken.
55 if(type==qQUIT && !Playing)
3961 return;
3962
3963 55 bool from_menu = is_sys_pal;
3964
3965
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55 times.
55 if(!from_menu)
3966 {
3967 55 music_pause();
3968 55 pause_all_sfx();
3969 55 sys_mouse();
3970 55 }
3971 55 enter_sys_pal();
3972 55 clear_keybuf();
3973
3974
2/2
✓ Branch 0 taken 42 times.
✓ Branch 1 taken 13 times.
55 if (replay_version_check(0, 10))
3975 13 replay_poll();
3976
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55 times.
55 if (replay_is_replaying())
3977 55 replay_peek_quit();
3978
3979
1/2
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
55 if (!replay_is_replaying())
3980 switch(type)
3981 {
3982 case qQUIT:
3983 onQuit();
3984 break;
3985
3986 case qRESET:
3987 onReset();
3988 break;
3989
3990 case qEXIT:
3991 onExit();
3992 break;
3993 }
3994
3995
1/2
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
55 if(Quit)
3996 {
3997 55 kill_sfx();
3998 55 music_stop();
3999 55 exit_sys_pal();
4000 55 update_hw_screen();
4001 55 }
4002 else
4003 {
4004 exit_sys_pal();
4005 if(!from_menu)
4006 {
4007 music_resume();
4008 resume_all_sfx();
4009 }
4010 }
4011
4012
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55 times.
55 if(!from_menu)
4013 55 game_mouse();
4014 55 eat_buttons();
4015
4016 55 zc_readrawkey(KEY_ESC);
4017
4018 55 zc_readrawkey(KEY_ENTER);
4019 55 }
4020
4021 //----------------------------------------------------------------
4022
4023 int32_t onNoWalls()
4024 {
4025 cheats_enqueue(Cheat::Walls);
4026 return D_O_K;
4027 }
4028
4029 int32_t onIgnoreSideview()
4030 {
4031 cheats_enqueue(Cheat::IgnoreSideView);
4032 return D_O_K;
4033 }
4034
4035 18303615 int32_t input_idle(bool checkmouse)
4036 {
4037 static int32_t mx, my, mz, mb;
4038
4039
4/6
✓ Branch 0 taken 18303615 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4900347 times.
✓ Branch 3 taken 13403268 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 4900347 times.
23203962 if(keypressed() || zc_key_pressed() ||
4040
4/8
✓ Branch 0 taken 4900347 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4900347 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4900347 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4900347 times.
✗ Branch 7 not taken.
4900347 (checkmouse && (mx != mouse_x || my != mouse_y || mz != mouse_z || mb != mouse_b)))
4041 {
4042 13403268 idle_count = 0;
4043
4044
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13403268 times.
13403268 if(active_count < MAX_ACTIVE)
4045 {
4046 13403268 ++active_count;
4047 13403268 }
4048 13403268 }
4049
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4900347 times.
4900347 else if(idle_count < MAX_IDLE)
4050 {
4051 4900347 ++idle_count;
4052 4900347 active_count = 0;
4053 4900347 }
4054
4055 18303615 mx = mouse_x;
4056 18303615 my = mouse_y;
4057 18303615 mz = mouse_z;
4058 18303615 mb = mouse_b;
4059
4060 18303615 return idle_count;
4061 }
4062
4063 int32_t onGoFast()
4064 {
4065 cheats_enqueue(Cheat::Fast);
4066 return D_O_K;
4067 }
4068
4069 int32_t onKillCheat()
4070 {
4071 cheats_enqueue(Cheat::Kill);
4072 return D_O_K;
4073 }
4074
4075 int32_t onSecretsCheat()
4076 {
4077 cheats_enqueue(Cheat::TrigSecrets);
4078 return D_O_K;
4079 }
4080 int32_t onSecretsCheatPerm()
4081 {
4082 cheats_enqueue(Cheat::TrigSecretsPerm);
4083 return D_O_K;
4084 }
4085
4086 int32_t onShowLayer0()
4087 {
4088 show_layer_0 = !show_layer_0;
4089 return D_O_K;
4090 }
4091 int32_t onShowLayer1()
4092 {
4093 show_layer_1 = !show_layer_1;
4094 return D_O_K;
4095 }
4096 int32_t onShowLayer2()
4097 {
4098 show_layer_2 = !show_layer_2;
4099 return D_O_K;
4100 }
4101 int32_t onShowLayer3()
4102 {
4103 show_layer_3 = !show_layer_3;
4104 return D_O_K;
4105 }
4106 int32_t onShowLayer4()
4107 {
4108 show_layer_4 = !show_layer_4;
4109 return D_O_K;
4110 }
4111 int32_t onShowLayer5()
4112 {
4113 show_layer_5 = !show_layer_5;
4114 return D_O_K;
4115 }
4116 int32_t onShowLayer6()
4117 {
4118 show_layer_6 = !show_layer_6;
4119 return D_O_K;
4120 }
4121 int32_t onShowLayerO()
4122 {
4123 show_layer_over=!show_layer_over;
4124 return D_O_K;
4125 }
4126 int32_t onShowLayerP()
4127 {
4128 show_layer_push=!show_layer_push;
4129 return D_O_K;
4130 }
4131 int32_t onShowLayerS()
4132 {
4133 show_sprites=!show_sprites;
4134 return D_O_K;
4135 }
4136 int32_t onShowLayerF()
4137 {
4138 show_ffcs=!show_ffcs;
4139 return D_O_K;
4140 }
4141 int32_t onShowLayerW()
4142 {
4143 show_walkflags=!show_walkflags;
4144 if(show_walkflags)
4145 show_effectflags = false;
4146 return D_O_K;
4147 }
4148 int32_t onShowLayerE()
4149 {
4150 show_effectflags=!show_effectflags;
4151 if(show_effectflags)
4152 show_walkflags = false;
4153 return D_O_K;
4154 }
4155 int32_t onShowFFScripts()
4156 {
4157 show_ff_scripts=!show_ff_scripts;
4158 return D_O_K;
4159 }
4160 int32_t onShowHitboxes()
4161 {
4162 show_hitboxes=!show_hitboxes;
4163 return D_O_K;
4164 }
4165 int32_t onShowInfoOpacity()
4166 {
4167 info_opacity = vbound(getnumber("Debug Info Opacity",info_opacity),0,255);
4168 zc_set_config("zc","debug_info_opacity",info_opacity);
4169 return D_O_K;
4170 }
4171
4172 int32_t onLightSwitch()
4173 {
4174 cheats_enqueue(Cheat::Light);
4175 return D_O_K;
4176 }
4177
4178 int32_t onGoTo();
4179 int32_t onGoToComplete();
4180
4181 18303615 bool handle_close_btn_quit()
4182 {
4183
1/2
✓ Branch 0 taken 18303615 times.
✗ Branch 1 not taken.
18303615 if(close_button_quit)
4184 {
4185 close_button_quit=false;
4186 f_Quit(qEXIT);
4187 }
4188 18303615 return (exiting_program = Quit==qEXIT);
4189 }
4190
4191 18303615 void syskeys()
4192 {
4193 18303615 update_system_keys();
4194
4195 int32_t oldtitle_version;
4196
4197 18303615 poll_joystick();
4198
4199 18303615 handle_close_btn_quit();
4200
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18303615 times.
18303615 if(Quit == qEXIT) return;
4201
4202
2/10
✓ Branch 0 taken 18303615 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 18303615 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
18303615 if(rMbtn() || (gui_mouse_b() && !mouse_down && ClickToFreeze &&!disableClickToFreeze))
4203 {
4204 System();
4205 }
4206
4207 18303615 mouse_down=gui_mouse_b();
4208
4209
1/2
✓ Branch 0 taken 18303615 times.
✗ Branch 1 not taken.
18303615 if(zc_read_system_key(KEY_F1))
4210 {
4211 if(zc_get_system_key(KEY_ZC_LCONTROL) || zc_get_system_key(KEY_ZC_RCONTROL))
4212 {
4213 halt=!halt;
4214 //zinit.subscreen=(zinit.subscreen+1)%ssdtMAX;
4215 }
4216 else
4217 {
4218 Throttlefps=!Throttlefps;
4219 zc_set_config(cfg_sect,"throttlefps", (int32_t)Throttlefps);
4220 }
4221 }
4222
4223
1/2
✓ Branch 0 taken 18303615 times.
✗ Branch 1 not taken.
18303615 if(zc_read_system_key(KEY_F2))
4224 {
4225 ShowFPS=!ShowFPS;
4226 zc_set_config(cfg_sect,"showfps",(int32_t)ShowFPS);
4227 }
4228
4229
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 18303615 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
18303615 if(zc_read_system_key(KEY_F3) && Playing) Paused=!Paused;
4230
4231
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 18303615 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
18303615 if(zc_read_system_key(KEY_F4) && Playing)
4232 {
4233 Paused=true;
4234 Advance=true;
4235 }
4236
4237
1/2
✓ Branch 0 taken 18303615 times.
✗ Branch 1 not taken.
18303615 if(zc_read_system_key(KEY_F6)) onTryQuit();
4238
4239 #ifndef ALLEGRO_MACOSX
4240
1/2
✓ Branch 0 taken 18303615 times.
✗ Branch 1 not taken.
18303615 if(zc_read_system_key(KEY_F9)) f_Quit(qRESET);
4241
4242
1/2
✓ Branch 0 taken 18303615 times.
✗ Branch 1 not taken.
18303615 if(zc_read_system_key(KEY_F10)) f_Quit(qEXIT);
4243 #else
4244 if(zc_read_system_key(KEY_F7)) f_Quit(qRESET);
4245
4246 if(zc_read_system_key(KEY_F8)) f_Quit(qEXIT);
4247 #endif
4248
1/8
✗ Branch 0 not taken.
✓ Branch 1 taken 18303615 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
18303615 if(zc_read_system_key(KEY_F5)&&(Playing && currscr<128 && DMaps[currdmap].flags&dmfVIEWMAP)) onSaveMapPic();
4249
4250
1/2
✓ Branch 0 taken 18303615 times.
✗ Branch 1 not taken.
18303615 if (zc_read_system_key(KEY_F12))
4251 {
4252 onSnapshot();
4253 }
4254
4255
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 18303615 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
18303615 if(debug_enabled && zc_read_system_key(KEY_TAB))
4256 set_debug(!get_debug());
4257
4258
1/2
✓ Branch 0 taken 18303615 times.
✗ Branch 1 not taken.
18303615 if(CheatModifierKeys())
4259 {
4260 for(Cheat c = (Cheat)1; c < Cheat::Last; c = (Cheat)(c+1))
4261 {
4262 if(!bindable_cheat(c))
4263 continue;
4264 if(get_debug() || cheat >= cheat_lvl(c))
4265 {
4266 if(checkcheat(c))
4267 cheats_hit_bind(c);
4268 }
4269 }
4270 }
4271
4272
1/2
✓ Branch 0 taken 18303615 times.
✗ Branch 1 not taken.
18303615 if(volkeys)
4273 {
4274 if(zc_read_system_key(KEY_PGUP)) master_volume(-1,midi_volume+8);
4275
4276 if(zc_read_system_key(KEY_PGDN)) master_volume(-1,midi_volume==255?248:midi_volume-8);
4277
4278 if(zc_read_system_key(KEY_HOME)) master_volume(digi_volume+8,-1);
4279
4280 if(zc_read_system_key(KEY_END)) master_volume(digi_volume==255?248:digi_volume-8,-1);
4281 }
4282
4283
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 18303615 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
18303615 if(!get_debug() || !SystemKeys || replay_is_replaying())
4284 18303615 goto bottom;
4285
4286 if(zc_readkey(KEY_P)) Paused=!Paused;
4287
4288 if(zc_readkey(KEY_A))
4289 {
4290 Paused=true;
4291 Advance=true;
4292 }
4293
4294 if(zc_readkey(KEY_G)) db=(db==999)?0:999;
4295 #ifndef ALLEGRO_MACOSX
4296 if(zc_readkey(KEY_F8)) Showpal=!Showpal;
4297
4298 if(zc_readkey(KEY_F7))
4299 {
4300 Matrix(ss_speed, ss_density, 0);
4301 game_pal();
4302 }
4303 #else
4304 // The reason these are different on Mac in the first place is that
4305 // the OS doesn't let us use F9 and F10...
4306 if(zc_readkey(KEY_F10)) Showpal=!Showpal;
4307
4308 if(zc_readkey(KEY_F9))
4309 {
4310 Matrix(ss_speed, ss_density, 0);
4311 game_pal();
4312 }
4313 #endif
4314 if(zc_readkey(KEY_PLUS_PAD) || zc_readkey(KEY_EQUALS))
4315 {
4316 //change containers
4317 if(zc_getkey(KEY_ZC_LCONTROL) || zc_getkey(KEY_ZC_RCONTROL))
4318 {
4319 //magic containers
4320 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4321 {
4322 game->set_maxmagic(zc_min(game->get_maxmagic()+game->get_mp_per_block(),game->get_mp_per_block()*8));
4323 }
4324 else
4325 {
4326 game->set_maxlife(zc_min(game->get_maxlife()+game->get_hp_per_heart(),game->get_hp_per_heart()*24));
4327 }
4328 }
4329 else
4330 {
4331 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4332 {
4333 game->set_magic(zc_min(game->get_magic()+1,game->get_maxmagic()));
4334 }
4335 else
4336 {
4337 game->set_life(zc_min(game->get_life()+1,game->get_maxlife()));
4338 }
4339 }
4340 }
4341
4342 if(zc_readkey(KEY_MINUS_PAD) || zc_readkey(KEY_MINUS))
4343 {
4344 //change containers
4345 if(zc_getkey(KEY_ZC_LCONTROL) || zc_getkey(KEY_ZC_RCONTROL))
4346 {
4347 //magic containers
4348 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4349 {
4350 game->set_maxmagic(zc_max(game->get_maxmagic()-game->get_mp_per_block(),0));
4351 game->set_magic(zc_min(game->get_maxmagic(), game->get_magic()));
4352 //heart containers
4353 }
4354 else
4355 {
4356 game->set_maxlife(zc_max(game->get_maxlife()-game->get_hp_per_heart(),game->get_hp_per_heart()));
4357 game->set_life(zc_min(game->get_maxlife(), game->get_life()));
4358 }
4359 }
4360 else
4361 {
4362 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4363 {
4364 game->set_magic(zc_max(game->get_magic()-1,0));
4365 }
4366 else
4367 {
4368 game->set_life(zc_max(game->get_life()-1,0));
4369 }
4370 }
4371 }
4372
4373 if(zc_readkey(KEY_COMMA)) jukebox(currmidi-1);
4374
4375 if(zc_readkey(KEY_STOP)) jukebox(currmidi+1);
4376
4377 verifyBothWeapons();
4378
4379 bottom:
4380
4381
1/2
✓ Branch 0 taken 18303615 times.
✗ Branch 1 not taken.
18303615 if(input_idle(true) > after_time())
4382 {
4383 Matrix(ss_speed, ss_density, 0);
4384 game_pal();
4385 }
4386 18303615 }
4387
4388 1113811 void checkQuitKeys()
4389 {
4390 #ifndef ALLEGRO_MACOSX
4391
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1113811 times.
1113811 if(key[KEY_F9]) f_Quit(qRESET);
4392
4393
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1113811 times.
1113811 if(key[KEY_F10]) f_Quit(qEXIT);
4394 #else
4395 if(key[KEY_F7]) f_Quit(qRESET);
4396
4397 if(key[KEY_F8]) f_Quit(qEXIT);
4398 #endif
4399 1113811 }
4400
4401 18303815 bool CheatModifierKeys()
4402 {
4403 // Cheats are replayed via the X cheat step, no need to check for keyboard input
4404 // to trigger cheats.
4405
2/2
✓ Branch 0 taken 18303515 times.
✓ Branch 1 taken 300 times.
18303815 if (replay_is_replaying())
4406 18303515 return false;
4407
4408
3/4
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 200 times.
✓ Branch 2 taken 100 times.
✗ Branch 3 not taken.
300 if ( ( cheat_modifier_keys[0] > 0 && key[cheat_modifier_keys[0]] ) ||
4409
2/2
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 100 times.
200 ( cheat_modifier_keys[1] > 0 && key[cheat_modifier_keys[1]] ) ||
4410
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 100 times.
100 (cheat_modifier_keys[0] <= 0 && cheat_modifier_keys[1] <= 0))
4411 {
4412
0/4
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
200 if ( ( cheat_modifier_keys[2] <= 0 || key[cheat_modifier_keys[2]] ) ||
4413 ( cheat_modifier_keys[3] > 0 && key[cheat_modifier_keys[3]] ) ||
4414 (cheat_modifier_keys[2] <= 0 && cheat_modifier_keys[3] <= 0))
4415 {
4416 return true;
4417 }
4418 }
4419 100 return false;
4420 18303615 }
4421
4422 //99:05:54, for some reason?
4423 #define OLDMAXTIME 21405240
4424 //9000:00:00, the highest even-thousand hour fitting within 32b signed. This is 375 *DAYS*.
4425 #define MAXTIME 1944000000
4426
4427 18304952 void advanceframe(bool allowwavy, bool sfxcleanup, bool allowF6Script)
4428 {
4429
1/2
✓ Branch 0 taken 18304952 times.
✗ Branch 1 not taken.
18304952 if(zcmusic!=NULL)
4430 {
4431 zcmusic_poll();
4432 }
4433 18304952 zcmixer_update(zcmixer, emusic_volume, FFCore.usr_music_volume, get_qr(qr_OLD_SCRIPT_VOLUME));
4434
4435 18304952 updatescr(allowwavy);
4436
4437 18304952 Advance=false;
4438
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 18304952 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 18304952 times.
18304952 while(Paused && !Advance && !Quit)
4439 {
4440 // have to call this, otherwise we'll get an infinite loop
4441 syskeys();
4442 if(allowF6Script)
4443 {
4444 FFCore.runF6Engine();
4445 }
4446
4447 #ifdef _WIN32
4448
4449 if(use_dwm_flush)
4450 {
4451 do_DwmFlush();
4452 }
4453
4454 #endif
4455
4456 // to keep music playing
4457 if(zcmusic!=NULL)
4458 {
4459 zcmusic_poll();
4460 }
4461
4462 update_hw_screen();
4463 }
4464
4465
2/2
✓ Branch 0 taken 18303654 times.
✓ Branch 1 taken 1298 times.
18304952 if(Quit)
4466 1298 return;
4467
4468
3/4
✓ Branch 0 taken 17790932 times.
✓ Branch 1 taken 512722 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 17790932 times.
18303654 if(Playing && game->get_time()<unsigned(get_qr(qr_GREATER_MAX_TIME) ? MAXTIME : OLDMAXTIME))
4469 17790932 game->change_time(1);
4470
4471 // Many mistakes have been make re: inputs, and we are stuck with many replays relying on those mistakes.
4472
4473 18303654 bool should_reset_down_state = !get_qr(qr_BROKEN_INPUT_DOWN_STATE);
4474
2/2
✓ Branch 0 taken 8594040 times.
✓ Branch 1 taken 9709614 times.
18303654 if (replay_version_check(0, 16))
4475 9709614 should_reset_down_state = replay_version_check(11, 16);
4476
2/2
✓ Branch 0 taken 14976005 times.
✓ Branch 1 taken 3327649 times.
18303654 if (should_reset_down_state)
4477 {
4478
2/2
✓ Branch 0 taken 59897682 times.
✓ Branch 1 taken 3327649 times.
63225331 for (int i = 0; i < ZC_CONTROL_STATES; i++)
4479 59897682 down_control_states[i] = raw_control_state[i];
4480 3327649 }
4481
4482
2/2
✓ Branch 0 taken 39 times.
✓ Branch 1 taken 18303615 times.
18303654 if (replay_is_active())
4483 {
4484
2/2
✓ Branch 0 taken 1545418 times.
✓ Branch 1 taken 16758197 times.
18303615 if (replay_version_check(3))
4485 16758197 replay_poll();
4486
4487
4/4
✓ Branch 0 taken 7388911 times.
✓ Branch 1 taken 10914704 times.
✓ Branch 2 taken 100535 times.
✓ Branch 3 taken 7288376 times.
18303615 if (replay_version_check(11) || replay_version_check(6, 8))
4488 11015239 replay_peek_input();
4489 18303615 }
4490
4491 18303654 load_control_called_this_frame = false;
4492
4493 18303654 poll_keyboard();
4494 18303654 update_keys();
4495
4496 18303654 ++frame;
4497
4498
2/2
✓ Branch 0 taken 139 times.
✓ Branch 1 taken 18303515 times.
18303654 if (replay_is_replaying())
4499 18303515 replay_do_cheats();
4500 18303654 syskeys();
4501
4502 // The mouse variables can change from the mouse thread at anytime during a frame,
4503 // so save the result at the start so that replaying is consistent.
4504 18303654 script_mouse_x = gui_mouse_x();
4505 18303654 script_mouse_y = gui_mouse_y();
4506 18303654 script_mouse_z = mouse_z;
4507 18303654 script_mouse_b = mouse_b;
4508
4509 // Cheats used via the System menu (called by syskeys) will call cheats_enqueue. syskeys
4510 // is called just above, and in the paused loop above, so the queue-and-defer-slightly
4511 // approach here means it doesn't matter which call adds the cheat.
4512 18303654 cheats_execute_queued();
4513
4514
2/2
✓ Branch 0 taken 139 times.
✓ Branch 1 taken 18303515 times.
18303654 if (replay_is_replaying())
4515 18303515 replay_peek_quit();
4516
2/2
✓ Branch 0 taken 18303599 times.
✓ Branch 1 taken 55 times.
18303654 if (GameFlags & GAMEFLAG_TRYQUIT)
4517 55 replay_step_quit(0);
4518
2/2
✓ Branch 0 taken 3324 times.
✓ Branch 1 taken 18300330 times.
18303654 if(allowF6Script)
4519 18300330 FFCore.runF6Engine();
4520
2/2
✓ Branch 0 taken 712 times.
✓ Branch 1 taken 18302942 times.
18303654 if (Quit)
4521 712 replay_step_quit(Quit);
4522
4523 #ifdef _WIN32
4524
4525 if(use_dwm_flush)
4526 {
4527 do_DwmFlush();
4528 }
4529
4530 #endif
4531
4532
2/2
✓ Branch 0 taken 208647 times.
✓ Branch 1 taken 18095007 times.
18303654 if(sfxcleanup)
4533 18095007 sfx_cleanup();
4534
4535 18303654 jit_poll();
4536
4537 #ifdef __EMSCRIPTEN__
4538 // Yield the main thread back to the browser occasionally.
4539 if (is_headless())
4540 {
4541 static int rate = 10000;
4542 static int force_yield = rate;
4543 if (force_yield++ >= rate)
4544 {
4545 force_yield = 0;
4546 emscripten_sleep(0);
4547 }
4548 }
4549 #endif
4550
4551
4/6
✓ Branch 0 taken 230 times.
✓ Branch 1 taken 18303424 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 230 times.
✓ Branch 4 taken 230 times.
✗ Branch 5 not taken.
18303654 static bool test_mode_auto_restart = zc_get_config("zeldadx", "test_mode_auto_restart", false);
4552
3/4
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 18303554 times.
✓ Branch 2 taken 100 times.
✗ Branch 3 not taken.
18303654 if (zqtesting_mode && test_mode_auto_restart)
4553 {
4554 static auto last_write_time = fs::last_write_time(qstpath);
4555 static auto last_check = std::chrono::system_clock::now();
4556
4557 if (std::chrono::system_clock::now() - last_check > 200ms)
4558 {
4559 last_check = std::chrono::system_clock::now();
4560 auto write_time = fs::last_write_time(qstpath);
4561 if (last_write_time != write_time)
4562 {
4563 last_write_time = write_time;
4564 disableClickToFreeze = false;
4565 Quit = qRESET;
4566 replay_quit();
4567 }
4568 }
4569 }
4570 18304952 }
4571
4572 589 void zapout()
4573 {
4574 589 set_clip_rect(scrollbuf, 0, 0, scrollbuf->w, scrollbuf->h);
4575 589 blit(framebuf,scrollbuf,0,0,256,0,256,224);
4576
4577 589 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4578 589 script_drawing_commands.Clear();
4579
4580 // zap out
4581
2/2
✓ Branch 0 taken 589 times.
✓ Branch 1 taken 14136 times.
14725 for(int32_t i=1; i<=24; i++)
4582 {
4583 14136 draw_fuzzy(i);
4584 14136 advanceframe(true);
4585
4586
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14136 times.
14136 if(Quit)
4587 {
4588 break;
4589 }
4590 14136 }
4591 589 }
4592
4593 587 void zapin()
4594 {
4595 587 FFCore.warpScriptCheck();
4596 587 draw_screen(tmpscr);
4597 587 set_clip_rect(scrollbuf, 0, 0, scrollbuf->w, scrollbuf->h);
4598 587 blit(framebuf,scrollbuf,0,0,256,0,256,224);
4599
4600 // zap out
4601 587 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4602
2/2
✓ Branch 0 taken 587 times.
✓ Branch 1 taken 14088 times.
14675 for(int32_t i=24; i>=1; i--)
4603 {
4604 14088 draw_fuzzy(i);
4605 14088 advanceframe(true);
4606
4607
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14088 times.
14088 if(Quit)
4608 {
4609 break;
4610 }
4611 14088 }
4612 587 }
4613
4614
4615 235 void wavyout(bool showhero)
4616 {
4617 235 draw_screen(tmpscr, showhero);
4618
4619 235 BITMAP *wavebuf = create_bitmap_ex(8,288,224);
4620 235 clear_to_color(wavebuf,0);
4621 235 blit(framebuf,wavebuf,0,0,16,0,256,224);
4622
4623 static PALETTE wavepal;
4624
4625 int32_t ofs;
4626 235 int32_t amplitude=8;
4627
4628 235 int32_t wavelength=4;
4629 235 double palpos=0, palstep=4, palstop=126;
4630
4631 235 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4632
2/2
✓ Branch 0 taken 234 times.
✓ Branch 1 taken 9845 times.
10079 for(int32_t i=0; i<168; i+=wavelength)
4633 {
4634
2/2
✓ Branch 0 taken 2520320 times.
✓ Branch 1 taken 9845 times.
2530165 for(int32_t l=0; l<256; l++)
4635 {
4636 2520320 wavepal[l].r=vbound(int32_t(RAMpal[l].r+((palpos/palstop)*(255-RAMpal[l].r))),0,255);
4637 2520320 wavepal[l].g=vbound(int32_t(RAMpal[l].g+((palpos/palstop)*(255-RAMpal[l].g))),0,255);
4638 2520320 wavepal[l].b=vbound(int32_t(RAMpal[l].b+((palpos/palstop)*(255-RAMpal[l].b))),0,255);
4639 2520320 }
4640
4641 9845 palpos+=palstep;
4642
4643
1/2
✓ Branch 0 taken 9845 times.
✗ Branch 1 not taken.
9845 if(palpos>=0)
4644 {
4645 9845 hw_palette = &wavepal;
4646 9845 update_hw_pal = true;
4647 9845 }
4648 else
4649 {
4650 hw_palette = &RAMpal;
4651 update_hw_pal = true;
4652 }
4653
4654
2/2
✓ Branch 0 taken 1653960 times.
✓ Branch 1 taken 9845 times.
1663805 for(int32_t j=0; j+playing_field_offset<224; j++)
4655 {
4656
2/2
✓ Branch 0 taken 423413760 times.
✓ Branch 1 taken 1653960 times.
425067720 for(int32_t k=0; k<256; k++)
4657 {
4658 423413760 ofs=0;
4659
4660
4/4
✓ Branch 0 taken 206448640 times.
✓ Branch 1 taken 216965120 times.
✓ Branch 2 taken 103224320 times.
✓ Branch 3 taken 103224320 times.
423413760 if((j<i)&&(j&1))
4661 {
4662 103224320 ofs=int32_t(zc::math::Sin((double(i+j)*2*PI/168.0))*amplitude);
4663 103224320 }
4664
4665 423413760 framebuf->line[j+playing_field_offset][k]=wavebuf->line[j+playing_field_offset][k+ofs+16];
4666 423413760 }
4667 1653960 }
4668
4669 9845 advanceframe(true);
4670
4671
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 9844 times.
9845 if(Quit)
4672 1 break;
4673 9844 }
4674
4675 235 destroy_bitmap(wavebuf);
4676
4677 235 hw_palette = &RAMpal;
4678 235 update_hw_pal = true;
4679 235 }
4680
4681 232 void wavyin()
4682 {
4683 232 draw_screen(tmpscr);
4684
4685 232 BITMAP *wavebuf = create_bitmap_ex(8,288,224);
4686 232 clear_to_color(wavebuf,0);
4687 232 blit(framebuf,wavebuf,0,0,16,0,256,224);
4688
4689 static PALETTE wavepal;
4690
4691 232 refreshpal=false;
4692 int32_t ofs;
4693 232 int32_t amplitude=8;
4694 232 int32_t wavelength=4;
4695 232 double palpos=168, palstep=4, palstop=126;
4696
4697 232 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4698
2/2
✓ Branch 0 taken 231 times.
✓ Branch 1 taken 9703 times.
9934 for(int32_t i=0; i<168; i+=wavelength)
4699 {
4700
2/2
✓ Branch 0 taken 2483968 times.
✓ Branch 1 taken 9703 times.
2493671 for(int32_t l=0; l<256; l++)
4701 {
4702 2483968 wavepal[l].r=vbound(int32_t(RAMpal[l].r+((palpos/palstop)*(255-RAMpal[l].r))),0,255);
4703 2483968 wavepal[l].g=vbound(int32_t(RAMpal[l].g+((palpos/palstop)*(255-RAMpal[l].g))),0,255);
4704 2483968 wavepal[l].b=vbound(int32_t(RAMpal[l].b+((palpos/palstop)*(255-RAMpal[l].b))),0,255);
4705 2483968 }
4706
4707 9703 palpos-=palstep;
4708
4709
1/2
✓ Branch 0 taken 9703 times.
✗ Branch 1 not taken.
9703 if(palpos>=0)
4710 {
4711 9703 hw_palette = &wavepal;
4712 9703 update_hw_pal = true;
4713 9703 }
4714 else
4715 {
4716 hw_palette = &RAMpal;
4717 update_hw_pal = true;
4718 }
4719
4720
2/2
✓ Branch 0 taken 1630104 times.
✓ Branch 1 taken 9703 times.
1639807 for(int32_t j=0; j+playing_field_offset<224; j++)
4721 {
4722
2/2
✓ Branch 0 taken 417306624 times.
✓ Branch 1 taken 1630104 times.
418936728 for(int32_t k=0; k<256; k++)
4723 {
4724 417306624 ofs=0;
4725
4726
4/4
✓ Branch 0 taken 211158272 times.
✓ Branch 1 taken 206148352 times.
✓ Branch 2 taken 106821120 times.
✓ Branch 3 taken 104337152 times.
417306624 if((j<(167-i))&&(j&1))
4727 {
4728 104337152 ofs=int32_t(zc::math::Sin((double(i+j)*2*PI/168.0))*amplitude);
4729 104337152 }
4730
4731 417306624 framebuf->line[j+playing_field_offset][k]=wavebuf->line[j+playing_field_offset][k+ofs+16];
4732 417306624 }
4733 1630104 }
4734
4735 9703 advanceframe(true);
4736
4737
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 9702 times.
9703 if(Quit)
4738 1 break;
4739 9702 }
4740
4741 232 destroy_bitmap(wavebuf);
4742
4743 232 hw_palette = &RAMpal;
4744 232 update_hw_pal = true;
4745 232 }
4746
4747 4332 void blackscr(int32_t fcnt,bool showsubscr)
4748 {
4749 4332 reset_pal_cycling();
4750 4332 script_drawing_commands.Clear();
4751
4752 4332 FFCore.warpScriptCheck();
4753 4332 bool showtime = game->should_show_time();
4754
2/2
✓ Branch 0 taken 4325 times.
✓ Branch 1 taken 129517 times.
133842 while(fcnt>0)
4755 {
4756 129517 clear_bitmap(framebuf);
4757
4758
2/2
✓ Branch 0 taken 59250 times.
✓ Branch 1 taken 70267 times.
129517 if(showsubscr)
4759 {
4760 70267 put_passive_subscr(framebuf,0,passive_subscreen_offset,showtime,sspUP);
4761
3/4
✓ Branch 0 taken 70267 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1230 times.
✓ Branch 3 taken 69037 times.
70267 if(get_qr(qr_SCRIPTDRAWSINWARPS) || (get_qr(qr_PASSIVE_SUBSCRIPT_RUNS_WHEN_GAME_IS_FROZEN)))
4762 {
4763 1230 do_script_draws(framebuf, tmpscr, 0, playing_field_offset);
4764 1230 }
4765 70267 }
4766
4767 129517 advanceframe(true);
4768
4769
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 129510 times.
129517 if(Quit)
4770 7 break;
4771
4772 129510 --fcnt;
4773 }
4774 4332 }
4775
4776 2636 void openscreen(int32_t shape)
4777 {
4778 2636 reset_pal_cycling();
4779 2636 black_opening_count=0;
4780
4781
3/4
✓ Branch 0 taken 522 times.
✓ Branch 1 taken 2114 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 522 times.
2636 if(COOLSCROLL || shape>-1)
4782 {
4783 2114 open_black_opening(HeroX()+8, (HeroY()-HeroZ()-HeroFakeZ())+8+playing_field_offset, true, shape);
4784 2114 return;
4785 }
4786 else
4787 {
4788 522 Hero.setDontDraw(true);
4789 522 show_subscreen_dmap_dots=false;
4790 522 show_subscreen_numbers=false;
4791 522 show_subscreen_life=false;
4792 }
4793
4794 522 int32_t x=128;
4795
4796 522 FFCore.warpScriptCheck();
4797
2/2
✓ Branch 0 taken 522 times.
✓ Branch 1 taken 41760 times.
42282 for(int32_t i=0; i<80; i++)
4798 {
4799 41760 draw_screen(tmpscr);
4800 41760 x=128-(((i*128/80)/8)*8);
4801
4802
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 41760 times.
41760 if(x>0)
4803 {
4804 41760 rectfill(framebuf,0,playing_field_offset,x,167+playing_field_offset,0);
4805 41760 rectfill(framebuf,256-x,playing_field_offset,255,167+playing_field_offset,0);
4806 41760 }
4807
4808 41760 advanceframe(true);
4809
4810
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 41760 times.
41760 if(Quit)
4811 {
4812 break;
4813 }
4814 41760 }
4815
4816 522 Hero.setDontDraw(false);
4817 522 show_subscreen_items=true;
4818 522 show_subscreen_dmap_dots=true;
4819 522 show_subscreen_numbers=true;
4820 522 show_subscreen_life=true;
4821 2636 }
4822
4823 4 void closescreen(int32_t shape)
4824 {
4825 4 reset_pal_cycling();
4826 4 black_opening_count=0;
4827
4828
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
4 if(COOLSCROLL || shape>-1)
4829 {
4830 4 close_black_opening(HeroX()+8, (HeroY()-HeroZ()-HeroFakeZ())+8+playing_field_offset, true, shape);
4831 4 return;
4832 }
4833 else
4834 {
4835 Hero.setDontDraw(true);
4836 show_subscreen_dmap_dots=false;
4837 show_subscreen_numbers=false;
4838 // show_subscreen_items=false;
4839 show_subscreen_life=false;
4840 }
4841
4842 int32_t x=128;
4843
4844 FFCore.warpScriptCheck();
4845 for(int32_t i=79; i>=0; --i)
4846 {
4847 draw_screen(tmpscr);
4848 x=128-(((i*128/80)/8)*8);
4849
4850 if(x>0)
4851 {
4852 rectfill(framebuf,0,playing_field_offset,x,167+playing_field_offset,0);
4853 rectfill(framebuf,256-x,playing_field_offset,255,167+playing_field_offset,0);
4854 }
4855
4856 advanceframe(true);
4857
4858 if(Quit)
4859 {
4860 break;
4861 }
4862 }
4863
4864 Hero.setDontDraw(false);
4865 show_subscreen_items=true;
4866 show_subscreen_dmap_dots=true;
4867 4 }
4868
4869 296 int32_t TriforceCount()
4870 {
4871 296 int32_t c=0;
4872
4873
2/2
✓ Branch 0 taken 2368 times.
✓ Branch 1 taken 296 times.
2664 for(int32_t i=1; i<=8; i++)
4874
2/2
✓ Branch 0 taken 484 times.
✓ Branch 1 taken 1884 times.
4252 if(game->lvlitems[i]&liTRIFORCE)
4875 1884 ++c;
4876
4877 296 return c;
4878 }
4879
4880 int32_t onCustomGame()
4881 {
4882 int32_t file = getsaveslot();
4883
4884 if(file < 0)
4885 return D_O_K;
4886
4887 bool ret = (custom_game(file)!=0);
4888 return ret ? D_CLOSE : D_O_K;
4889 }
4890
4891 int32_t onContinue()
4892 {
4893 return D_CLOSE;
4894 }
4895
4896 int32_t onThrottleFPS()
4897 {
4898 Throttlefps = !Throttlefps;
4899 zc_set_config(cfg_sect,"throttlefps", (int32_t)Throttlefps);
4900 return D_O_K;
4901 }
4902
4903 int32_t onWinPosSave()
4904 {
4905 SaveWinPos = !SaveWinPos;
4906 zc_set_config(cfg_sect,"save_window_position",(int32_t)SaveWinPos);
4907 return D_O_K;
4908 }
4909 int32_t onIntegerScaling()
4910 {
4911 scaleForceInteger = !scaleForceInteger;
4912 zc_set_config("zeldadx","scaling_force_integer",(int)scaleForceInteger);
4913 return D_O_K;
4914 }
4915 int32_t onStretchGame()
4916 {
4917 stretchGame = !stretchGame;
4918 zc_set_config("zeldadx","stretch_game_area",stretchGame?1:0);
4919 return D_O_K;
4920 }
4921
4922 int32_t onClickToFreeze()
4923 {
4924 ClickToFreeze = !ClickToFreeze;
4925 zc_set_config(cfg_sect,"clicktofreeze", (int32_t)ClickToFreeze);
4926 return D_O_K;
4927 }
4928
4929 int32_t OnSaveZCConfig()
4930 {
4931 if(jwin_alert3(
4932 "Save Configuration",
4933 "Are you sure that you wish to save your present configuration settings?",
4934 "This will overwrite your prior settings!",
4935 NULL,
4936 "&Yes",
4937 "&No",
4938 NULL,
4939 'y',
4940 'n',
4941 0,
4942 get_zc_font(font_lfont)) == 1)
4943 {
4944 save_game_configs();
4945 return D_O_K;
4946 }
4947 else return D_O_K;
4948 }
4949
4950 int32_t OnnClearQuestDir()
4951 {
4952 auto current_path = fs::current_path() / "quests";
4953 if(jwin_alert3(
4954 "Clear Current Directory Cache",
4955 "Are you sure that you wish to reset where ZC Player looks for quests?",
4956 fmt::format("The new directory will be: {}", current_path.string()).c_str(),
4957 NULL,
4958 "&Yes",
4959 "&No",
4960 NULL,
4961 'y',
4962 'n',
4963 0,
4964 get_zc_font(font_lfont)) == 1)
4965 {
4966 zc_set_config("zeldadx","quest_dir","quests");
4967 flush_config_file();
4968 strcpy(qstdir,"quests");
4969 #ifdef __EMSCRIPTEN__
4970 em_sync_fs();
4971 #endif
4972 return D_O_K;
4973 }
4974 else return D_O_K;
4975 }
4976
4977 int32_t onConsole()
4978 {
4979 if ( !console_enabled )
4980 {
4981 AlertDialog("ZC Console",
4982 "Open the ZC Console?"
4983 "\nThis will display any messages logged by scripts,"
4984 " including errors.",
4985 [&](bool ret,bool)
4986 {
4987 if(ret)
4988 {
4989 FFCore.ZScriptConsole(true);
4990 }
4991 }).show();
4992 return D_O_K;
4993 }
4994 else
4995 {
4996 FFCore.ZScriptConsole(false);
4997 return D_O_K;
4998 }
4999 }
5000
5001 int32_t onClrConsoleOnReload()
5002 {
5003 clearConsoleOnReload = !clearConsoleOnReload;
5004 zc_set_config("CONSOLE","clear_console_on_reload",clearConsoleOnReload?1:0);
5005 return D_O_K;
5006 }
5007 int32_t onClrConsoleOnLoad()
5008 {
5009 clearConsoleOnLoad = !clearConsoleOnLoad;
5010 zc_set_config("CONSOLE","clear_console_on_load",clearConsoleOnLoad?1:0);
5011 return D_O_K;
5012 }
5013
5014
5015 int32_t onFrameSkip()
5016 {
5017 FrameSkip = !FrameSkip;
5018 return D_O_K;
5019 }
5020
5021 int32_t onSaveDragResize()
5022 {
5023 SaveDragResize = !SaveDragResize;
5024 zc_set_config(cfg_sect,"save_drag_resize",(int32_t)SaveDragResize);
5025 return D_O_K;
5026 }
5027
5028 int32_t onDragAspect()
5029 {
5030 DragAspect = !DragAspect;
5031 zc_set_config(cfg_sect,"drag_aspect",(int32_t)DragAspect);
5032 return D_O_K;
5033 }
5034
5035 int32_t onTransLayers()
5036 {
5037 TransLayers = !TransLayers;
5038 zc_set_config(cfg_sect,"translayers",(int32_t)TransLayers);
5039 return D_O_K;
5040 }
5041
5042 int32_t onNESquit()
5043 {
5044 NESquit = !NESquit;
5045 zc_set_config(cfg_sect,"fastquit",(int32_t)NESquit);
5046 return D_O_K;
5047 }
5048
5049 int32_t onVolKeys()
5050 {
5051 volkeys = !volkeys;
5052 zc_set_config(sfx_sect,"volkeys",(int32_t)volkeys);
5053 return D_O_K;
5054 }
5055
5056 int32_t onShowFPS()
5057 {
5058 ShowFPS = !ShowFPS;
5059 zc_set_config(cfg_sect,"showfps",(int32_t)ShowFPS);
5060 return D_O_K;
5061 }
5062
5063 int32_t onShowTime()
5064 {
5065 ShowGameTime = !ShowGameTime;
5066 zc_set_config(cfg_sect,"showtime",ShowGameTime);
5067 return D_O_K;
5068 }
5069
5070 2159826570 bool is_Fkey(int32_t k)
5071 {
5072
2/2
✓ Branch 0 taken 219643380 times.
✓ Branch 1 taken 1940183190 times.
2159826570 switch(k)
5073 {
5074 case KEY_F1:
5075 case KEY_F2:
5076 case KEY_F3:
5077 case KEY_F4:
5078 case KEY_F5:
5079 case KEY_F6:
5080 case KEY_F7:
5081 case KEY_F8:
5082 case KEY_F9:
5083 case KEY_F10:
5084 case KEY_F11:
5085 case KEY_F12:
5086 219643380 return true;
5087 }
5088
5089 1940183190 return false;
5090 2159826570 }
5091
5092 void kb_getkey(DIALOG *d);
5093
5094 //Used by all keyboard key settings dialogues.
5095 void kb_clearjoystick(DIALOG *d)
5096 {
5097 d->flags|=D_SELECTED;
5098
5099 jwin_button_proc(MSG_DRAW,d,0);
5100 jwin_draw_win(screen, (screen->w-160)/2, (screen->h-48)/2, 160, 48, FR_WIN);
5101 // text_mode(vc(11));
5102 textout_centre_ex(screen, font, "Press any key to clear", gui_bmp->w/2, gui_bmp->h/2 - 8, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5103 textout_centre_ex(screen, font, "ESC to cancel", gui_bmp->w/2, gui_bmp->h/2, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5104
5105 update_hw_screen();
5106
5107 clear_keybuf();
5108 int32_t k = next_press_key();
5109 clear_keybuf();
5110
5111 //shnarf
5112 //47=f1
5113 //59=esc
5114 // if(k>0 && k<123 && !((k>46)&&(k<60)))
5115 // *((int32_t*)d->dp3) = k;
5116 if ( k != 59 ) *((int32_t*)d->dp3) = 0;
5117
5118
5119 d->flags&=~D_SELECTED;
5120 }
5121
5122 //Clears key to 0.
5123 //Used by all keyboard key settings dialogues.
5124 void kb_clearkey(DIALOG *d);
5125
5126 int32_t d_j_clearbutton_proc(int32_t msg,DIALOG *d,int32_t c)
5127 {
5128 switch(msg)
5129 {
5130 case MSG_KEY:
5131 case MSG_CLICK:
5132
5133 kb_clearjoystick(d);
5134
5135 while(gui_mouse_b())
5136 {
5137 clear_keybuf();
5138 rest(1);
5139 }
5140
5141 return D_REDRAW;
5142 }
5143
5144 return jwin_button_proc(msg,d,c);
5145 }
5146
5147 int32_t d_kbutton_proc(int32_t msg,DIALOG *d,int32_t c);
5148 //Only used in keyboard settings dialogues to clear keys.
5149 int32_t d_k_clearbutton_proc(int32_t msg,DIALOG *d,int32_t c);
5150
5151 int32_t j_getbtn(DIALOG *d)
5152 {
5153 d->flags|=D_SELECTED;
5154 jwin_button_proc(MSG_DRAW,d,0);
5155 jwin_draw_win(screen, (screen->w-160)/2, (screen->h-48)/2, 160, 48, FR_WIN);
5156 // text_mode(vc(11));
5157 int32_t y = screen->h/2 - 12;
5158 textout_centre_ex(screen, font, "Press a button", screen->w/2, y, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5159 textout_centre_ex(screen, font, "ESC to cancel", screen->w/2, y+8, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5160 textout_centre_ex(screen, font, "SPACE to disable", screen->w/2, y+16, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5161
5162 update_hw_screen();
5163
5164 int32_t b = next_joy_input(true);
5165 if (b == -2)
5166 return D_CLOSE;
5167
5168 if(b>=0)
5169 *((int32_t*)d->dp3) = b;
5170
5171 d->flags&=~D_SELECTED;
5172
5173 return D_O_K;
5174 }
5175
5176 void j_getstick(DIALOG *d)
5177 {
5178 d->flags|=D_SELECTED;
5179 jwin_button_proc(MSG_DRAW,d,0);
5180 jwin_draw_win(screen, (screen->w-160)/2, (screen->h-48)/2, 160, 48, FR_WIN);
5181 // text_mode(vc(11));
5182 int32_t y = screen->h/2 - 12;
5183 textout_centre_ex(screen, font, "Move a stick (or DPAD)", screen->w/2, y, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5184 textout_centre_ex(screen, font, "ESC to cancel", screen->w/2, y+8, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5185 textout_centre_ex(screen, font, "SPACE to disable", screen->w/2, y+16, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5186
5187 update_hw_screen();
5188
5189 int32_t b = next_joy_input(false);
5190
5191 if(b>=0)
5192 *((int32_t*)d->dp3) = b;
5193
5194 d->flags&=~D_SELECTED;
5195 }
5196
5197 int32_t d_jbutton_proc(int32_t msg,DIALOG *d,int32_t c)
5198 {
5199 switch(msg)
5200 {
5201 case MSG_KEY:
5202 case MSG_CLICK:
5203
5204 int ret = j_getbtn(d);
5205 if (ret != D_O_K)
5206 return ret;
5207
5208 while(gui_mouse_b()) {
5209 rest(1);
5210 clear_keybuf();
5211 }
5212
5213 return D_REDRAW;
5214 }
5215
5216 return jwin_button_proc(msg,d,c);
5217 }
5218
5219 int32_t d_jstick_proc(int32_t msg,DIALOG *d,int32_t c)
5220 {
5221 switch(msg)
5222 {
5223 case MSG_KEY:
5224 case MSG_CLICK:
5225
5226 j_getstick(d);
5227
5228 while(gui_mouse_b()) {
5229 rest(1);
5230 clear_keybuf();
5231 }
5232
5233 return D_REDRAW;
5234 }
5235
5236 return jwin_button_proc(msg,d,c);
5237 }
5238
5239 //shnarf
5240 extern const char *key_str[];
5241 std::string get_keystr(int key);
5242
5243 const char *pan_str[4] = { " MONO", " 1/2", " 3/4", " FULL" };
5244
5245 static char str_a[80],str_b[80],str_s[80],str_m[80],str_l[80],str_r[80],str_p[80],str_ex1[80],str_ex2[80],str_ex3[80],str_ex4[80],
5246 str_leftmod1[80],str_leftmod2[80],str_rightmod1[80],str_rightmod2[80], str_left[80], str_right[80], str_up[80], str_down[80],
5247 str_primary_stick[80], str_secondary_stick[80];
5248
5249 int32_t d_stringloader(int32_t msg,DIALOG *d,int32_t c)
5250 {
5251 //these are here to bypass compiler warnings about unused arguments
5252 c=c;
5253
5254 if (d->w == 1)
5255 {
5256 if (!gamepad_dlg_cur_joystick || !al_get_joystick_active(gamepad_dlg_cur_joystick))
5257 {
5258 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
5259 return D_CLOSE;
5260 }
5261 }
5262
5263 if(msg==MSG_DRAW)
5264 {
5265 switch(d->w)
5266 {
5267 case 0:
5268 sprintf(str_a,"%03d\n%s",Akey,key_str[Akey]);
5269 sprintf(str_b,"%03d\n%s",Bkey,key_str[Bkey]);
5270 sprintf(str_s,"%03d\n%s",Skey,key_str[Skey]);
5271 sprintf(str_l,"%03d\n%s",Lkey,key_str[Lkey]);
5272 sprintf(str_r,"%03d\n%s",Rkey,key_str[Rkey]);
5273 sprintf(str_p,"%03d\n%s",Pkey,key_str[Pkey]);
5274 sprintf(str_ex1,"%03d\n%s",Exkey1,key_str[Exkey1]);
5275 sprintf(str_ex2,"%03d\n%s",Exkey2,key_str[Exkey2]);
5276 sprintf(str_ex3,"%03d\n%s",Exkey3,key_str[Exkey3]);
5277 sprintf(str_ex4,"%03d\n%s",Exkey4,key_str[Exkey4]);
5278 sprintf(str_up,"%03d\n%s",DUkey,key_str[DUkey]);
5279 sprintf(str_down,"%03d\n%s",DDkey,key_str[DDkey]);
5280 sprintf(str_left,"%03d\n%s",DLkey,key_str[DLkey]);
5281 sprintf(str_right,"%03d\n%s",DRkey,key_str[DRkey]);
5282 sprintf(str_leftmod1,"%03d\n%s",cheat_modifier_keys[0],key_str[cheat_modifier_keys[0]]);
5283 sprintf(str_leftmod2,"%03d\n%s",cheat_modifier_keys[1],key_str[cheat_modifier_keys[1]]);
5284 sprintf(str_rightmod1,"%03d\n%s",cheat_modifier_keys[2],key_str[cheat_modifier_keys[2]]);
5285 sprintf(str_rightmod2,"%03d\n%s",cheat_modifier_keys[3],key_str[cheat_modifier_keys[3]]);
5286 break;
5287
5288 case 1:
5289 sprintf(str_a,"%03d\n%s",Abtn,joybtn_name(Abtn));
5290 sprintf(str_b,"%03d\n%s",Bbtn,joybtn_name(Bbtn));
5291 sprintf(str_s,"%03d\n%s",Sbtn,joybtn_name(Sbtn));
5292 sprintf(str_l,"%03d\n%s",Lbtn,joybtn_name(Lbtn));
5293 sprintf(str_r,"%03d\n%s",Rbtn,joybtn_name(Rbtn));
5294 sprintf(str_m,"%03d\n%s",Mbtn,joybtn_name(Mbtn));
5295 sprintf(str_p,"%03d\n%s",Pbtn,joybtn_name(Pbtn));
5296 sprintf(str_ex1,"%03d\n%s",Exbtn1,joybtn_name(Exbtn1));
5297 sprintf(str_ex2,"%03d\n%s",Exbtn2,joybtn_name(Exbtn2));
5298 sprintf(str_ex3,"%03d\n%s",Exbtn3,joybtn_name(Exbtn3));
5299 sprintf(str_ex4,"%03d\n%s",Exbtn4,joybtn_name(Exbtn4));
5300 sprintf(str_up,"%03d\n%s",DUbtn,joybtn_name(DUbtn));
5301 sprintf(str_down,"%03d\n%s",DDbtn,joybtn_name(DDbtn));
5302 sprintf(str_left,"%03d\n%s",DLbtn,joybtn_name(DLbtn));
5303 sprintf(str_right,"%03d\n%s",DRbtn,joybtn_name(DRbtn));
5304 sprintf(str_primary_stick,"%03d\n%s",js_stick_1_x_stick,joystick_name(js_stick_1_x_stick));
5305 sprintf(str_secondary_stick,"%03d\n%s",js_stick_2_x_stick,joystick_name(js_stick_2_x_stick));
5306 sprintf(str_leftmod1,"%03d\n%s",cheat_modifier_keys[0],key_str[cheat_modifier_keys[0]]);
5307 sprintf(str_leftmod2,"%03d\n%s",cheat_modifier_keys[1],key_str[cheat_modifier_keys[1]]);
5308 sprintf(str_rightmod1,"%03d\n%s",cheat_modifier_keys[2],key_str[cheat_modifier_keys[2]]);
5309 sprintf(str_rightmod2,"%03d\n%s",cheat_modifier_keys[3],key_str[cheat_modifier_keys[3]]);
5310 break;
5311
5312 case 2:
5313 sprintf(str_a," %3d",midi_volume);
5314 sprintf(str_l," %3d",emusic_volume);
5315 sprintf(str_r," %3d",sfx_volume);
5316 strcpy(str_s,pan_str[pan_style]);
5317 sprintf(str_leftmod1,"%3d\n%s",cheat_modifier_keys[0],key_str[cheat_modifier_keys[0]]);
5318 sprintf(str_leftmod2,"%3d\n%s",cheat_modifier_keys[1],key_str[cheat_modifier_keys[1]]);
5319 sprintf(str_rightmod1,"%3d\n%s",cheat_modifier_keys[2],key_str[cheat_modifier_keys[2]]);
5320 sprintf(str_rightmod2,"%3d\n%s",cheat_modifier_keys[3],key_str[cheat_modifier_keys[3]]);
5321 break;
5322 }
5323 }
5324
5325 return D_O_K;
5326 }
5327
5328 int32_t set_vol(void *dp3, int32_t d2)
5329 {
5330 switch(((int32_t*)dp3)[0])
5331 {
5332 case 0:
5333 midi_volume = zc_min(d2<<3,255);
5334 break;
5335
5336 case 1:
5337 digi_volume = zc_min(d2<<3,255);
5338 break;
5339
5340 case 2:
5341 emusic_volume = zc_min(d2<<3,255);
5342 break;
5343
5344 case 3:
5345 sfx_volume = zc_min(d2<<3,255);
5346 break;
5347 }
5348
5349 // text_mode(vc(11));
5350 textprintf_right_ex(screen,get_zc_font(font_lfont_l), ((int32_t*)dp3)[1],((int32_t*)dp3)[2],jwin_pal[jcBOXFG],jwin_pal[jcBOX]," %3d",zc_min(d2<<3,255));
5351 return D_O_K;
5352 }
5353
5354 int32_t set_pan(void *dp3, int32_t d2)
5355 {
5356 pan_style = vbound(d2,0,3);
5357 // text_mode(vc(11));
5358 textout_right_ex(screen,get_zc_font(font_lfont_l), pan_str[pan_style],((int32_t*)dp3)[1],((int32_t*)dp3)[2],jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5359 return D_O_K;
5360 }
5361
5362 static int32_t gamepad_joys_list[] =
5363 {
5364 61,
5365 -1
5366 };
5367
5368 static int32_t gamepad_btn_list[] =
5369 {
5370 6,
5371 7,8,9,10,11,12,13,14,15,16,17,
5372 18,19,20,21,22,23,24,25,26,27,28,
5373 29,30,31,32,33,34,35,36,37,38,39,
5374 -1
5375 };
5376
5377 static int32_t gamepad_dirs_list[] =
5378 {
5379 40,41,42,43,
5380 44,45,46,47,
5381 48,49,50,51,
5382 52,53,54,55,
5383 56,57,58,59,
5384 60,
5385 -1
5386 };
5387
5388 static TABPANEL gamepad_tabs[] =
5389 {
5390 // (text)
5391 { (char *)"Controllers", D_SELECTED, gamepad_joys_list, 0, NULL },
5392 { (char *)"Buttons", 0, gamepad_btn_list, 0, NULL },
5393 { (char *)"Directions", 0, gamepad_dirs_list, 0, NULL },
5394 { NULL, 0, NULL, 0, NULL }
5395 };
5396
5397 const char *joy_list(int32_t index, int32_t *list_size)
5398 {
5399 if (index == -1)
5400 {
5401 *list_size = al_get_num_joysticks();
5402 return NULL;
5403 }
5404
5405 ALLEGRO_JOYSTICK* joy = al_get_joystick(index);
5406 if (!joy)
5407 {
5408 return "?";
5409 }
5410
5411 return al_get_joystick_name(joy);
5412 }
5413
5414 329 static ListData joy__list(joy_list, &font);
5415
5416 static int32_t d_joylist_proc(int32_t msg,DIALOG *d,int32_t c)
5417 {
5418 int32_t d2 = d->d2;
5419 int32_t ret = jwin_droplist_proc(msg,d,c);
5420
5421 if(d2!=d->d2)
5422 {
5423 joystick_index = d->d2;
5424 ret |= D_REDRAW_ALL;
5425 }
5426
5427 return ret;
5428 }
5429
5430 static DIALOG gamepad_dlg[] =
5431 {
5432 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
5433 { jwin_win_proc, 8, 24, 304, 256, 0, 0, 0, D_EXIT, 0, 0, (void *) "Gamepad Controls", NULL, NULL },
5434 { jwin_tab_proc, 8+4, 24+23,304-8,256-52,vc(0), vc(15), 0, 0, 0, 0, (void *) gamepad_tabs, NULL, (void *)gamepad_dlg },
5435 { d_stringloader, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5436 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5437 { jwin_button_proc, 90, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5438 { jwin_button_proc, 170, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5439 // 6
5440 { d_dummy_proc, 14, 61, 294, 192, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5441 // 7
5442 { jwin_ctext_proc, 92, 92-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_a, NULL, NULL },
5443 { jwin_ctext_proc, 92, 120-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_b, NULL, NULL },
5444 { jwin_ctext_proc, 92, 148-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5445 { jwin_ctext_proc, 92, 180-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex1, NULL, NULL },
5446 { jwin_ctext_proc, 92, 212-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex3, NULL, NULL },
5447 { jwin_ctext_proc, 237, 92-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_l, NULL, NULL },
5448 { jwin_ctext_proc, 237, 120-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_r, NULL, NULL },
5449 { jwin_ctext_proc, 237, 148-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_p, NULL, NULL },
5450 { jwin_ctext_proc, 237, 180-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex2, NULL, NULL },
5451 { jwin_ctext_proc, 237, 212-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex4, NULL, NULL },
5452 { jwin_ctext_proc, 92, 244-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_m, NULL, NULL },
5453 // 18
5454 { d_jbutton_proc, 22, 90-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "A", NULL, &Abtn},
5455 { d_jbutton_proc, 22, 118-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "B", NULL, &Bbtn},
5456 { d_jbutton_proc, 22, 146-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Start", NULL, &Sbtn},
5457 { d_jbutton_proc, 22, 178-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "X (EX1)", NULL, &Exbtn1},
5458 { d_jbutton_proc, 22, 210-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX3", NULL, &Exbtn3},
5459 { d_jbutton_proc, 167, 90-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "L", NULL, &Lbtn},
5460 { d_jbutton_proc, 167, 118-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "R", NULL, &Rbtn},
5461 { d_jbutton_proc, 167, 146-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Map", NULL, &Pbtn},
5462 { d_jbutton_proc, 167, 178-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Y (EX2)", NULL, &Exbtn2},
5463 { d_jbutton_proc, 167, 210-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX4", NULL, &Exbtn4},
5464 { d_jbutton_proc, 22, 242-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Menu", NULL, &Mbtn},
5465 // 29
5466 { d_j_clearbutton_proc, 22+91, 90-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Abtn},
5467 { d_j_clearbutton_proc, 22+91, 118-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Bbtn},
5468 { d_j_clearbutton_proc, 22+91, 146-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Sbtn},
5469 { d_j_clearbutton_proc, 22+91, 178-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn1},
5470 { d_j_clearbutton_proc, 22+91, 210-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn3},
5471 { d_j_clearbutton_proc, 167+91, 90-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Lbtn},
5472 { d_j_clearbutton_proc, 167+91, 118-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Rbtn},
5473 { d_j_clearbutton_proc, 167+91, 146-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Pbtn},
5474 { d_j_clearbutton_proc, 167+91, 178-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn2},
5475 { d_j_clearbutton_proc, 167+91, 210-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn4},
5476 { d_j_clearbutton_proc, 22+91, 242-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Mbtn},
5477 // 40
5478 { jwin_frame_proc, 14, 62, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5479 { jwin_frame_proc, 159, 62, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5480 { jwin_text_proc, 30, 68, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Vertical", NULL, NULL },
5481 { jwin_text_proc, 175, 68, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Horizontal", NULL, NULL },
5482 // 44
5483 { jwin_text_proc, 92, 84, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_up, NULL, NULL },
5484 { jwin_text_proc, 92, 112, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_down, NULL, NULL },
5485 { jwin_text_proc, 237, 84, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_left, NULL, NULL },
5486 { jwin_text_proc, 237, 112, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_right, NULL, NULL },
5487 // 48
5488 { d_jbutton_proc, 22, 82, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Up", NULL, &DUbtn },
5489 { d_jbutton_proc, 22, 110, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Down", NULL, &DDbtn },
5490 { d_jbutton_proc, 167, 82, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Left", NULL, &DLbtn },
5491 { d_jbutton_proc, 167, 110, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Right", NULL, &DRbtn },
5492 // 52
5493 { d_j_clearbutton_proc, 22+91, 82, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DUbtn},
5494 { d_j_clearbutton_proc, 22+91, 110, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DDbtn},
5495 { d_j_clearbutton_proc, 167+91, 82, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DLbtn},
5496 { d_j_clearbutton_proc, 167+91, 110, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DRbtn},
5497 // 56
5498 { jwin_check_proc, 22, 150, 147, 8, vc(14), vc(1), 0, 0, 1, 0, (void *) "Primary: Use Analog Stick (Ignore above and use below instead)", NULL, NULL },
5499 { d_jstick_proc, 22, 165, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Primary", NULL, &js_stick_1_x_stick },
5500 { d_jstick_proc, 22, 195, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Secondary", NULL, &js_stick_2_x_stick },
5501 { jwin_text_proc, 90, 165, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_primary_stick, NULL, NULL },
5502 { jwin_text_proc, 90, 195, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_secondary_stick, NULL, NULL },
5503
5504 // 61
5505 { d_joylist_proc, 22, 62, 150, 16, 0, 0, 0, 0, 0, 0, (void *) &joy__list, NULL, NULL },
5506
5507 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5508 };
5509
5510 static int32_t keyboard_keys_list[] =
5511 {
5512 6,7,8,9,10,
5513 11,12,13,14,15,16,17,18,19,20,
5514 21,22,23,24,25,26,27,28,29,30,
5515 31,32,33,34,35,36,37,38,39,40,
5516 -1
5517 };
5518
5519 static int32_t keyboard_dirs_list[] =
5520 {
5521 41,42,43,44,
5522 45,46,47,48,
5523 49,50,51,52,
5524 53,54,55,56,
5525 -1
5526 };
5527
5528 static int32_t keyboard_mods_list[] =
5529 {
5530 57,58,59,60,
5531 61,62,63,64,
5532 65,66,67,68,
5533 69,70,71,72,
5534 -1
5535 };
5536
5537 static TABPANEL keyboard_control_tabs[] =
5538 {
5539 // (text)
5540 { (char *)"Keys", D_SELECTED, keyboard_keys_list, 0, NULL },
5541 { (char *)"Directions", 0, keyboard_dirs_list, 0, NULL },
5542 { (char *)"Cheat Mods", 0, keyboard_mods_list, 0, NULL },
5543 { NULL, 0, NULL, 0, NULL }
5544 };
5545
5546 static DIALOG keyboard_control_dlg[] =
5547 {
5548 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
5549 { jwin_win_proc, 8, 39, 304, 240, 0, 0, 0, D_EXIT, 0, 0, (void *) "Keyboard Controls", NULL, NULL },
5550 { jwin_tab_proc, 8+4, 39+23,304-8,240-56,vc(0), vc(15), 0, 0, 0, 0, (void *) keyboard_control_tabs, NULL, (void *)keyboard_control_dlg },
5551 { d_stringloader, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5552 { jwin_button_proc, 90, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5553 { jwin_button_proc, 170, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5554 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5555 // Keys
5556 // 6
5557 { jwin_frame_proc, 14, 80, 148, 105, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5558 { jwin_frame_proc, 158, 80, 148, 105, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5559 { jwin_frame_proc, 14, 181, 292, 67, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5560 { jwin_text_proc, 30, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Standard", NULL, NULL },
5561 { jwin_text_proc, 175, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Extended", NULL, NULL },
5562 // 11
5563 { jwin_text_proc, 92-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_a, NULL, NULL },
5564 { jwin_text_proc, 92-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_b, NULL, NULL },
5565 { jwin_text_proc, 92-4, 158, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5566 { jwin_text_proc, 92-4, 190, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex1, NULL, NULL },
5567 { jwin_text_proc, 92-4, 222, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex3, NULL, NULL },
5568 { jwin_text_proc, 237-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_l, NULL, NULL },
5569 { jwin_text_proc, 237-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_r, NULL, NULL },
5570 { jwin_text_proc, 237-4, 158, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_p, NULL, NULL },
5571 { jwin_text_proc, 237-4, 190, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex2, NULL, NULL },
5572 { jwin_text_proc, 237-4, 222, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex4, NULL, NULL },
5573 // 21
5574 { d_kbutton_proc, 22, 100, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "A", NULL, &Akey},
5575 { d_kbutton_proc, 22, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "B", NULL, &Bkey},
5576 { d_kbutton_proc, 22, 156, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Start", NULL, &Skey},
5577 { d_kbutton_proc, 22, 188, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "X (EX1)", NULL, &Exkey1},
5578 { d_kbutton_proc, 22, 220, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX3", NULL, &Exkey3},
5579 { d_kbutton_proc, 167, 100, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "L", NULL, &Lkey},
5580 { d_kbutton_proc, 167, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "R", NULL, &Rkey},
5581 { d_kbutton_proc, 167, 156, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Map", NULL, &Pkey},
5582 { d_kbutton_proc, 167, 188, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Y (EX2)", NULL, &Exkey2},
5583 { d_kbutton_proc, 167, 220, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX4", NULL, &Exkey4},
5584 // 31
5585 { d_k_clearbutton_proc, 22+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Akey},
5586 { d_k_clearbutton_proc, 22+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Bkey},
5587 { d_k_clearbutton_proc, 22+91, 156, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Skey},
5588 { d_k_clearbutton_proc, 22+91, 188, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey1},
5589 { d_k_clearbutton_proc, 22+91, 220, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey3},
5590 { d_k_clearbutton_proc, 167+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Lkey},
5591 { d_k_clearbutton_proc, 167+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Rkey},
5592 { d_k_clearbutton_proc, 167+91, 156, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Pkey},
5593 { d_k_clearbutton_proc, 167+91, 188, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey2},
5594 { d_k_clearbutton_proc, 167+91, 220, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey4},
5595 // Dirs
5596 // 41
5597 { jwin_frame_proc, 14, 80, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5598 { jwin_frame_proc, 159, 80, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5599 { jwin_text_proc, 30, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Vertical", NULL, NULL },
5600 { jwin_text_proc, 175, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Horizontal", NULL, NULL },
5601 // 45
5602 { jwin_text_proc, 92-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_up, NULL, NULL },
5603 { jwin_text_proc, 92-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_down, NULL, NULL },
5604 { jwin_text_proc, 237-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_left, NULL, NULL },
5605 { jwin_text_proc, 237-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_right, NULL, NULL },
5606 // 49
5607 { d_kbutton_proc, 22, 100, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Up", NULL, &DUkey},
5608 { d_kbutton_proc, 22, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Down", NULL, &DDkey},
5609 { d_kbutton_proc, 167, 100, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Left", NULL, &DLkey},
5610 { d_kbutton_proc, 167, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Right", NULL, &DRkey},
5611 // 53
5612 { d_k_clearbutton_proc, 22+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DUkey},
5613 { d_k_clearbutton_proc, 22+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DDkey},
5614 { d_k_clearbutton_proc, 167+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DLkey},
5615 { d_k_clearbutton_proc, 167+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DRkey},
5616 // Mods
5617 // 57
5618 { jwin_frame_proc, 14, 80, 148, 140-58, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5619 { jwin_frame_proc, 158, 80, 148, 140-58, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5620 { jwin_text_proc, 30, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Left", NULL, NULL },
5621 { jwin_text_proc, 175, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Right", NULL, NULL },
5622 // 61
5623 { jwin_text_proc, 92-26, 101, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_leftmod1, NULL, NULL },
5624 { jwin_text_proc, 92-26, 129, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_rightmod1, NULL, NULL },
5625 { jwin_text_proc, 237-4-22,101, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_leftmod2, NULL, NULL },
5626 { jwin_text_proc, 237-4-22,129, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_rightmod2, NULL, NULL },
5627 // 65
5628 { d_kbutton_proc, 22, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Main", NULL, &cheat_modifier_keys[0]},
5629 { d_kbutton_proc, 22, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Second", NULL, &cheat_modifier_keys[2]},
5630 { d_kbutton_proc, 167, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Main", NULL, &cheat_modifier_keys[1]},
5631 { d_kbutton_proc, 167, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Second", NULL, &cheat_modifier_keys[3]},
5632 // 69
5633 { d_k_clearbutton_proc, 22+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[0]},
5634 { d_k_clearbutton_proc, 22+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[2]},
5635 { d_k_clearbutton_proc, 167+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[1]},
5636 { d_k_clearbutton_proc, 167+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[3]},
5637 // 73
5638 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5639 };
5640
5641 int32_t midi_dp[3] = {0,0,0};
5642 int32_t emus_dp[3] = {2,0,0};
5643 int32_t sfx_dp[3] = {3,0,0};
5644 int32_t pan_dp[3] = {0,0,0};
5645
5646 static DIALOG sound_dlg[] =
5647 {
5648 //(dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
5649 329 { jwin_win_proc, 0, 0, 320, 178, 0, 0, 0, D_EXIT, 0, 0, (void *) "Sound Settings", NULL, NULL },
5650 329 { d_stringloader, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5651 329 { jwin_button_proc, 58, 148, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5652 329 { jwin_button_proc, 138, 148, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5653 329 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5654 329 { jwin_frame_proc, 10, 28, 300, 112, 0, 0, 0, 0, FR_ETCHED, 0, NULL, NULL, NULL },
5655 329 { jwin_rtext_proc, 190, 40, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_a, NULL, NULL },
5656 329 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5657 329 { jwin_rtext_proc, 190, 56, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_l, NULL, NULL },
5658 329 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5659 // 10
5660 329 { jwin_rtext_proc, 190, 72, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_r, NULL, NULL },
5661 329 { jwin_rtext_proc, 190, 88, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_s, NULL, NULL },
5662 329 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5663 329 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5664 329 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5665 329 { jwin_slider_proc, 196, 40, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 32, 0, NULL, (void *) set_vol, midi_dp },
5666 329 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5667 329 { jwin_slider_proc, 196, 56, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 32, 0, NULL, (void *) set_vol, emus_dp },
5668 329 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5669 329 { jwin_slider_proc, 196, 72, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 32, 0, NULL, (void *) set_vol, sfx_dp },
5670 //20
5671 329 { jwin_slider_proc, 196, 88, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 3, 0, NULL, (void *) set_pan, pan_dp },
5672 329 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5673 329 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5674 329 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5675 329 { jwin_text_proc, 17, 40, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "MIDI Volume", NULL, NULL },
5676 329 { jwin_text_proc, 17, 56, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Music Volume (Enhanced Music)", NULL, NULL },
5677 329 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5678 329 { jwin_text_proc, 17, 72, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "SFX Volume", NULL, NULL },
5679 329 { jwin_text_proc, 17, 88, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "SFX Pan", NULL, NULL },
5680 329 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5681 //30
5682 329 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5683 329 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5684 329 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5685 };
5686
5687 char zc_builddate[80];
5688 char zc_aboutstr[80];
5689
5690 static DIALOG about_dlg[] =
5691 {
5692 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
5693 { jwin_win_proc, 68, 52, 184, 154, 0, 0, 0, D_EXIT, 0, 0, (void *) "About", NULL, NULL },
5694 { jwin_button_proc, 140, 176, 41, 21, vc(14), 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5695 { jwin_ctext_proc, 160, 84, 0, 8, vc(0), vc(11), 0, 0, 0, 0, zc_aboutstr, NULL, NULL },
5696 { jwin_ctext_proc, 160, 92, 0, 8, vc(0) , vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5697 { jwin_ctext_proc, 160, 100, 0, 8, vc(0) , vc(11), 0, 0, 0, 0, zc_builddate, NULL, NULL },
5698 { jwin_text_proc, 88, 124, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Coded by:", NULL, NULL },
5699 { jwin_text_proc, 88, 132, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) " Phantom Menace", NULL, NULL },
5700 { jwin_text_proc, 88, 144, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Produced by:", NULL, NULL },
5701 { jwin_text_proc, 88, 152, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) " Armageddon Games", NULL, NULL },
5702 { jwin_frame_proc, 80, 117, 160, 50, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5703 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5704 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5705 };
5706
5707
5708 static DIALOG quest_dlg[] =
5709 {
5710 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
5711 { jwin_win_proc, 68, 25, 184, 190, 0, 0, 0, D_EXIT, 0, 0, (void *) "Quest Info", NULL, NULL },
5712 { jwin_edit_proc, 84, 54, 152, 16, 0, 0, 0, D_READONLY, 100, 0, NULL, NULL, NULL },
5713 { jwin_text_proc, 89, 84, 141, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Number:", NULL, NULL },
5714 { jwin_text_proc, 152, 84, 24, 8, vc(7), vc(11), 0, 0, 0, 0, str_a, NULL, NULL },
5715 { jwin_text_proc, 89, 94, 141, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Version:", NULL, NULL },
5716 { jwin_text_proc, 160, 94, 64, 8, vc(7), vc(11), 0, 0, 0, 0, header_version_nul_term, NULL, NULL },
5717 { jwin_text_proc, 89, 104, 141, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "ZQ Version:", NULL, NULL },
5718 { jwin_text_proc, 130, 104, 64, 8, vc(7), vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5719 { jwin_text_proc, 84, 126, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Title:", NULL, NULL },
5720 { jwin_textbox_proc, 84, 136, 152, 24, 0, 0, 0, 0, 0, 0, QHeader.title, NULL, NULL },
5721 { jwin_text_proc, 84, 168, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Author:", NULL, NULL },
5722 { jwin_textbox_proc, 84, 178, 152, 24, 0, 0, 0, 0, 0, 0, QHeader.author, NULL, NULL },
5723 { jwin_frame_proc, 84, 79, 152, 38, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5724 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5725 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5726 };
5727
5728 static DIALOG triforce_dlg[] =
5729 {
5730 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
5731 { jwin_win_proc, 72, 64, 177, 105, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Triforce Pieces", NULL, NULL },
5732 // 1
5733 { jwin_check_proc, 129, 94, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "1", NULL, NULL },
5734 { jwin_check_proc, 129, 104, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "2", NULL, NULL },
5735 { jwin_check_proc, 129, 114, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "3", NULL, NULL },
5736 { jwin_check_proc, 129, 124, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "4", NULL, NULL },
5737 { jwin_check_proc, 172, 94, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "5", NULL, NULL },
5738 { jwin_check_proc, 172, 104, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "6", NULL, NULL },
5739 { jwin_check_proc, 172, 114, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "7", NULL, NULL },
5740 { jwin_check_proc, 172, 124, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "8", NULL, NULL },
5741 // 9
5742 { jwin_button_proc, 90, 144, 61, 21, vc(0), vc(11), 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
5743 { jwin_button_proc, 170, 144, 61, 21, vc(0), vc(11), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5744 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5745 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5746 };
5747
5748 int32_t onToggleRecordingNewSaves()
5749 {
5750 if (zc_get_config("zeldadx", "replay_new_saves", false))
5751 {
5752 zc_set_config("zeldadx", "replay_new_saves", false);
5753 }
5754 else
5755 {
5756 zc_set_config("zeldadx", "replay_new_saves", true);
5757 jwin_alert("Recording", "Newly created saves will be recorded and written to a replay file.",
5758 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
5759 }
5760 return D_O_K;
5761 }
5762
5763 #ifdef HAS_CURL
5764 int32_t onToggleAutoUploadReplays()
5765 {
5766 if (zc_get_config("zeldadx", "replay_upload", false))
5767 {
5768 zc_set_config("zeldadx", "replay_upload", false);
5769 }
5770 else
5771 {
5772 zc_set_config("zeldadx", "replay_upload", true);
5773 jwin_alert("Replays", "Replays will be automatically uploaded. This helps development by",
5774 " preventing bugs and simplifying bug reports.",
5775 "Upload will happen no more than once a week when closing ZC",
5776 "OK",NULL,13,27,get_zc_font(font_lfont));
5777
5778 if (!zc_get_config("zeldadx", "replay_new_saves", false))
5779 onToggleRecordingNewSaves();
5780 }
5781 return D_O_K;
5782 }
5783
5784 int32_t onUploadReplays()
5785 {
5786 if(jwin_alert3(
5787 "Upload replays",
5788 "Upload your replays now to assist in development?",
5789 NULL,
5790 NULL,
5791 "&Yes",
5792 "&No",
5793 NULL,
5794 'y',
5795 'n',
5796 0,
5797 get_zc_font(font_lfont)) == 1)
5798 {
5799 int num_uploaded = replay_upload();
5800 jwin_alert("Upload replays", fmt::format("Uploaded {} replays", num_uploaded).c_str(),
5801 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
5802 }
5803 return D_O_K;
5804 }
5805
5806 int32_t onClearUploadCache()
5807 {
5808 if(jwin_alert3(
5809 "Upload replays",
5810 "Clear the upload cache?",
5811 "This simply deletes replays/state.json. There's no harm in doing this, but",
5812 "likely is not necessary.",
5813 "&Yes",
5814 "&No",
5815 NULL,
5816 'y',
5817 'n',
5818 0,
5819 get_zc_font(font_lfont)) == 1)
5820 {
5821 replay_upload_clear_cache();
5822 }
5823 return D_O_K;
5824 }
5825 #endif
5826
5827 int32_t onToggleSnapshotAllFrames()
5828 {
5829 replay_set_snapshot_all_frames(!replay_is_snapshot_all_frames());
5830 return D_O_K;
5831 }
5832
5833 int32_t onStopReplayOrRecord()
5834 {
5835 if (replay_is_replaying())
5836 {
5837 replay_quit();
5838 }
5839 else if (replay_get_mode() == ReplayMode::Record)
5840 {
5841 if (!replay_get_meta_bool("test_mode"))
5842 {
5843 jwin_alert("Recording", "You cannot stop recording a save file.",
5844 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
5845 return D_CLOSE;
5846 }
5847
5848 if (jwin_alert("Stop Recording",
5849 "Save replay to disk and stop recording?",
5850 "This will stop the recording.",
5851 NULL,
5852 "Yes","No",13,27,get_zc_font(font_lfont)) != 1)
5853 return D_CLOSE;
5854
5855 replay_save();
5856 replay_stop();
5857 }
5858 return D_O_K;
5859 }
5860
5861 static int32_t handle_on_load_replay(ReplayMode mode)
5862 {
5863 bool ctrl = CHECK_CTRL_CMD;
5864 if (Playing)
5865 {
5866 if (jwin_alert("Replay - Warning!",
5867 "Loading a replay will exit the current game.",
5868 "All unsaved progress will be lost.",
5869 "Do you wish to continue?",
5870 "Yes","No",13,27,get_zc_font(font_lfont)) != 1)
5871 return D_CLOSE;
5872 }
5873
5874 std::string mode_string = replay_mode_to_string(mode);
5875 mode_string[0] = std::toupper(mode_string[0]);
5876
5877 std::string line_1 = "Select a replay file to play back.";
5878 std::string line_2 = "You won't be able to save, and it won't effect existing saves.";
5879 std::string line_3 = "You can stop the replay and take over manually any time.";
5880 if (mode == ReplayMode::Update)
5881 {
5882 line_1 = "Select a replay file to update.";
5883 line_2 = "WARNING: be sure to back up the zplay file";
5884 line_3 = "and verify that the updated replay works as expected!";
5885 }
5886
5887 if (jwin_alert(mode_string.c_str(),
5888 line_1.c_str(),
5889 line_2.c_str(),
5890 line_3.c_str(),
5891 "OK","Nevermind",13,27,get_zc_font(font_lfont)) == 1)
5892 {
5893 std::string replay_path = "replays/";
5894 if(ctrl && devpwd())
5895 replay_path = "../../tests/replays/";
5896 std::string prompt = fmt::format("Load Replay ({})", REPLAY_EXTENSION);
5897 if (auto result = prompt_for_existing_file(prompt, REPLAY_EXTENSION, nullptr, replay_path))
5898 replay_path = *result;
5899 else
5900 return D_CLOSE;
5901
5902 replay_quit();
5903 load_replay_file_deferred(mode, replay_path);
5904 Quit = qRESET;
5905 return D_CLOSE;
5906 }
5907 return D_O_K;
5908 }
5909
5910 int32_t onLoadReplay()
5911 {
5912 return handle_on_load_replay(ReplayMode::Replay);
5913 }
5914
5915 int32_t onLoadReplayAssert()
5916 {
5917 return handle_on_load_replay(ReplayMode::Assert);
5918 }
5919
5920 int32_t onLoadReplayUpdate()
5921 {
5922 return handle_on_load_replay(ReplayMode::Update);
5923 }
5924
5925 int32_t onSaveReplay()
5926 {
5927 if (replay_get_mode() == ReplayMode::Record)
5928 {
5929 if (!replay_get_meta_bool("test_mode"))
5930 {
5931 if (jwin_alert("Save Replay",
5932 "This will save a copy of the replay up to this point.",
5933 "The official replay file will be untouched.",
5934 "Do you wish to continue?",
5935 "Yes","No",13,27,get_zc_font(font_lfont)) != 1)
5936 {
5937 return D_CLOSE;
5938 }
5939
5940 std::string replay_path = replay_get_replay_path().string();
5941 std::string prompt = fmt::format("Save Replay ({})", REPLAY_EXTENSION);
5942 if (auto result = prompt_for_new_file(prompt, REPLAY_EXTENSION, nullptr, replay_path))
5943 replay_path = *result;
5944 else
5945 return D_CLOSE;
5946
5947 if (fileexists(replay_path.c_str()))
5948 {
5949 jwin_alert("Save Replay", "You cannot overwrite an existing file.",
5950 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
5951 return D_CLOSE;
5952 }
5953
5954 replay_save(replay_path);
5955 }
5956 else
5957 {
5958 replay_save();
5959 }
5960 }
5961 return D_O_K;
5962 }
5963
5964 enum
5965 {
5966 MENUID_REPLAY_RECORDNEW,
5967 MENUID_REPLAY_STOP,
5968 MENUID_REPLAY_SAVE,
5969 MENUID_REPLAY_SNAP_ALL,
5970 MENUID_REPLAY_AUTOUPLOAD,
5971 MENUID_REPLAY_UPLOAD,
5972 MENUID_REPLAY_CLEARUPLOADCACHE,
5973 };
5974
1/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
329 static NewMenu replay_menu
5975 4277 {
5976
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Record new saves", onToggleRecordingNewSaves, MENUID_REPLAY_RECORDNEW },
5977
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 {},
5978
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Stop replay", onStopReplayOrRecord, MENUID_REPLAY_STOP },
5979
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Load replay", onLoadReplay },
5980
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Load replay (assert)", onLoadReplayAssert },
5981
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Load replay (update)", onLoadReplayUpdate },
5982
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Save replay", onSaveReplay, MENUID_REPLAY_SAVE },
5983
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Snapshot all frames", onToggleSnapshotAllFrames, MENUID_REPLAY_SNAP_ALL },
5984 #ifdef HAS_CURL
5985
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 {},
5986
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Auto upload replays", onToggleAutoUploadReplays, MENUID_REPLAY_AUTOUPLOAD },
5987
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Upload replays", onUploadReplays, MENUID_REPLAY_UPLOAD },
5988
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Clear upload cache", onClearUploadCache, MENUID_REPLAY_CLEARUPLOADCACHE },
5989 #endif
5990 };
5991
5992 static DIALOG credits_dlg[] =
5993 {
5994 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
5995 { jwin_win_proc, 40, 38, 241, 173, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "ZQuest Classic Credits", NULL, NULL },
5996 { jwin_frame_proc, 47, 65, 227, 115, vc(15), vc(1), 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
5997 { d_bitmap_proc, 49, 67, 222, 110, vc(15), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
5998 { jwin_button_proc, 140, 184, 41, 21, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5999 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6000 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6001 };
6002
6003 329 static ListData dmap_list(dmaplist, &font);
6004
6005 static DIALOG goto_dlg[] =
6006 {
6007 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
6008 { jwin_win_proc, 48, 25, 205, 100, 0, 0, 0, D_EXIT, 0, 0, (void *) "Goto Location", NULL, NULL },
6009 { jwin_button_proc, 90, 176-78, 61, 21, vc(14), 0, 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6010 { jwin_button_proc, 170, 176-78, 61, 21, vc(14), 0, 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
6011 { jwin_text_proc, 55, 129-75, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "DMap:", NULL, NULL },
6012 { jwin_droplist_proc, 88, 126-75, 160, 16, 0, 0, 0, 0, 0, 0, (void *) &dmap_list, NULL, NULL },
6013 { jwin_text_proc, 55, 149-75, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Screen:", NULL, NULL },
6014 { jwin_edit_proc, 132, 146-75, 91, 16, 0, 0, 0, 0, 2, 0, NULL, NULL, NULL },
6015 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6016 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6017 };
6018
6019 int32_t onGoTo()
6020 {
6021 bool music = false;
6022 music = music;
6023 sprintf(cheat_goto_screen_str,"%X",cheat_goto_screen);
6024
6025 goto_dlg[0].dp2=get_zc_font(font_lfont);
6026 goto_dlg[4].d2=cheat_goto_dmap;
6027 goto_dlg[6].dp=cheat_goto_screen_str;
6028
6029 clear_keybuf();
6030
6031 large_dialog(goto_dlg);
6032
6033 if(do_zqdialog(goto_dlg,4)==1)
6034 {
6035 int dmap = goto_dlg[4].d2;
6036 int screen = zc_xtoi(cheat_goto_screen_str);
6037 int adjusted_screen = screen + DMaps[dmap].xoff;
6038 if (adjusted_screen < 0 || adjusted_screen >= 128)
6039 {
6040 InfoDialog("Invalid screen", fmt::format("The screen {:02X} is out of bounds.", adjusted_screen)).show();
6041 }
6042 else
6043 {
6044 cheats_enqueue(Cheat::GoTo, dmap, screen);
6045 }
6046 };
6047
6048 return D_O_K;
6049 }
6050
6051 int32_t onGoToComplete()
6052 {
6053 if(!Playing)
6054 {
6055 return D_O_K;
6056 }
6057
6058 enter_sys_pal();
6059 music_pause();
6060 pause_all_sfx();
6061 onGoTo();
6062 eat_buttons();
6063
6064 zc_readrawkey(KEY_ESC);
6065
6066 exit_sys_pal();
6067 music_resume();
6068 resume_all_sfx();
6069 return D_O_K;
6070 }
6071
6072 int32_t onCredits()
6073 {
6074 return D_O_K;
6075 }
6076
6077 const char *midilist(int32_t index, int32_t *list_size)
6078 {
6079 if(index<0)
6080 {
6081 *list_size=0;
6082
6083 for(int32_t i=0; i<MAXMIDIS; i++)
6084 if(tunes[i].data)
6085 ++(*list_size);
6086
6087 return NULL;
6088 }
6089
6090 int32_t i=0,m=0;
6091
6092 while(m<=index && i<=MAXMIDIS)
6093 {
6094 if(tunes[i].data)
6095 ++m;
6096
6097 ++i;
6098 }
6099
6100 --i;
6101
6102 if(i==MAXMIDIS && m<index)
6103 return "(null)";
6104
6105 return tunes[i].title;
6106 }
6107
6108 /* ------- MIDI info stuff -------- */
6109
6110 char *text;
6111 midi_info *zmi;
6112 bool dialog_running;
6113 bool listening;
6114
6115 void get_info(int32_t index);
6116
6117 int32_t d_midilist_proc(int32_t msg,DIALOG *d,int32_t c)
6118 {
6119 int32_t d2 = d->d2;
6120 int32_t ret = jwin_droplist_proc(msg,d,c);
6121
6122 if(d2!=d->d2)
6123 {
6124 get_info(d->d2);
6125 }
6126
6127 return ret;
6128 }
6129
6130 int32_t d_listen_proc(int32_t msg,DIALOG *d,int32_t c)
6131 {
6132 /* 'd->d1' is offset from 'd' in DIALOG array to midilist proc */
6133
6134 int32_t ret = jwin_button_proc(msg,d,c);
6135
6136 if(ret == D_CLOSE)
6137 {
6138 // get current midi index
6139 int32_t index = (d+(d->d1))->d2;
6140 int32_t i=0, m=0;
6141
6142 while(m<=index && i<=MAXMIDIS)
6143 {
6144 if(tunes[i].data)
6145 ++m;
6146
6147 ++i;
6148 }
6149
6150 --i;
6151 jukebox(i);
6152 listening = true;
6153 ret = D_O_K;
6154 }
6155
6156 return ret;
6157 }
6158
6159 int32_t d_savemidi_proc(int32_t msg,DIALOG *d,int32_t c)
6160 {
6161 /* 'd->d1' is offset from 'd' in DIALOG array to midilist proc */
6162
6163 int32_t ret = jwin_button_proc(msg,d,c);
6164
6165 if(ret == D_CLOSE)
6166 {
6167 // get current midi index
6168 int32_t index = (d+(d->d1))->d2;
6169 int32_t i=0, m=0;
6170
6171 while(m<=index && i<=MAXMIDIS)
6172 {
6173 if(tunes[i].data)
6174 ++m;
6175
6176 ++i;
6177 }
6178
6179 --i;
6180
6181 char title[40] = "Save MIDI: ";
6182 static EXT_LIST list[] =
6183 {
6184 { (char *)"MIDI files (*.mid)", (char *)"mid" },
6185 { NULL, NULL }
6186 };
6187
6188 strcpy(title+11, tunes[i].title);
6189 title[39] = '\0';
6190
6191 std::string fname;
6192 if (auto result = prompt_for_new_file(title, "", list, "tune.mid"))
6193 fname = *result;
6194 else
6195 goto done;
6196
6197 if(exists(fname.c_str()))
6198 {
6199 if(jwin_alert(title, fname.c_str(), "already exists.", "Overwrite it?", "&Yes","&No",'y','n',get_zc_font(font_lfont))==2)
6200 goto done;
6201 }
6202
6203 // save midi i
6204
6205 if (save_midi(fname.c_str(), tunes[i].data) != 0)
6206 jwin_alert(title, "Error saving MIDI to", fname.c_str(), NULL, "Darn", NULL,13,27,get_zc_font(font_lfont));
6207
6208 done:
6209 chop_path(fname.data());
6210 ret = D_REDRAW;
6211 }
6212
6213 return ret;
6214 }
6215
6216 329 static ListData midi_list(midilist, &font);
6217
6218 static DIALOG midi_dlg[] =
6219 {
6220 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
6221 { jwin_win_proc, 8, 28, 304, 184, 0, 0, 0, D_EXIT, 0, 0, (void *) "MIDI Info", NULL, NULL },
6222 { jwin_text_proc, 32, 60, 40, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Tune:", NULL, NULL },
6223 { d_midilist_proc, 80, 56, 192, 16, 0, 0, 0, 0, 0, 0, (void *) &midi_list, NULL, NULL },
6224 { jwin_textbox_proc, 15, 80, 290, 96, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6225 { d_listen_proc, 24, 183, 72, 21, 0, 0, 'l', D_EXIT, -2, 0, (void *) "&Listen", NULL, NULL },
6226 { d_savemidi_proc, 108, 183, 72, 21, 0, 0, 's', D_EXIT, -3, 0, (void *) "&Save", NULL, NULL },
6227 { jwin_button_proc, 236, 183, 61, 21, 0, 0, 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
6228 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6229 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6230 };
6231
6232 void get_info(int32_t index)
6233 {
6234 int32_t i=0, m=0;
6235
6236 while(m<=index && i<=MAXMIDIS)
6237 {
6238 if(tunes[i].data)
6239 ++m;
6240
6241 ++i;
6242 }
6243
6244 --i;
6245
6246 if(i==MAXMIDIS && m<index)
6247 strcpy(text,"(null)");
6248 else
6249 {
6250 get_midi_info(tunes[i].data,zmi);
6251 get_midi_text(tunes[i].data,zmi,text);
6252 }
6253
6254 midi_dlg[0].dp2=get_zc_font(font_lfont);
6255 midi_dlg[3].dp = text;
6256 midi_dlg[3].d1 = midi_dlg[3].d2 = 0;
6257 midi_dlg[5].flags = (tunes[i].flags&tfDISABLESAVE) ? D_DISABLED : D_EXIT;
6258
6259 if(dialog_running)
6260 {
6261 jwin_textbox_proc(MSG_DRAW,midi_dlg+3,0);
6262 d_savemidi_proc(MSG_DRAW,midi_dlg+5,0);
6263 }
6264 }
6265
6266 int32_t onMIDICredits()
6267 {
6268 text = (char*)malloc(4096);
6269 zmi = (midi_info*)malloc(sizeof(midi_info));
6270
6271 if(!text || !zmi)
6272 {
6273 jwin_alert(NULL,"Not enough memory",NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
6274 return D_O_K;
6275 }
6276
6277 bool do_pause_midi = midi_pos >= 0 && currmidi;
6278 auto restore_midi = currmidi;
6279 if(do_pause_midi)
6280 {
6281 paused_midi_pos = midi_pos;
6282 stop_midi();
6283 midi_suspended = midissuspHALTED;
6284 }
6285
6286 midi_dlg[0].dp2=get_zc_font(font_lfont);
6287 midi_dlg[2].d1 = 0;
6288 midi_dlg[2].d2 = 0;
6289 midi_dlg[4].flags = D_EXIT;
6290 midi_dlg[5].flags = (tunes[midi_dlg[2].d1].flags&tfDISABLESAVE) ? D_DISABLED : D_EXIT;
6291
6292 listening = false;
6293 dialog_running=false;
6294 get_info(0);
6295
6296 dialog_running=true;
6297
6298 large_dialog(midi_dlg);
6299
6300 do_zqdialog(midi_dlg,0);
6301 dialog_running=false;
6302
6303 if(listening)
6304 music_stop();
6305
6306 if(do_pause_midi)
6307 {
6308 // TODO: this probably doesn't resume midis nicely when scrolling (or in some other inner-gameloop).
6309 midi_suspended = midissuspRESUME;
6310 currmidi = restore_midi;
6311 midi_pos = paused_midi_pos;
6312 }
6313
6314 if(text) free(text);
6315 if(zmi) free(zmi);
6316 return D_O_K;
6317 }
6318
6319 int32_t onAbout()
6320 {
6321 char buf1[80]={0};
6322 std::ostringstream oss;
6323 sprintf(buf1,ZC_PLAYER_NAME);
6324 oss << buf1 << '\n';
6325 sprintf(buf1,"Version: %s", getVersionString());
6326 oss << buf1 << '\n';
6327 sprintf(buf1,"Build Date: %s %s, %d at @ %s %s", dayextension(BUILDTM_DAY).c_str(), (char*)months[BUILDTM_MONTH], BUILDTM_YEAR, __TIME__, __TIMEZONE__);
6328 oss << buf1 << '\n';
6329 sprintf(buf1, "Built By: %s", DEV_SIGNOFF);
6330 oss << buf1 << '\n';
6331
6332 InfoDialog("About ZC", oss.str()).show();
6333 return D_O_K;
6334 }
6335
6336 int32_t onQuest()
6337 {
6338 char fname[100];
6339 strcpy(fname, get_filename(qstpath));
6340 quest_dlg[0].dp2=get_zc_font(font_lfont);
6341 quest_dlg[1].dp = fname;
6342
6343 if(QHeader.quest_number==0)
6344 sprintf(str_a,"Custom");
6345 else
6346 sprintf(str_a,"%d",QHeader.quest_number);
6347
6348 sprintf(str_s,"%s",QHeader.getVerStr());
6349
6350 quest_dlg[11].d1 = quest_dlg[9].d1 = 0;
6351 quest_dlg[11].d2 = quest_dlg[9].d2 = 0;
6352
6353 large_dialog(quest_dlg);
6354
6355 do_zqdialog(quest_dlg, 0);
6356 return D_O_K;
6357 }
6358
6359 void call_vidmode_dlg();
6360 int32_t onVidMode()
6361 {
6362 call_vidmode_dlg();
6363 return D_O_K;
6364 }
6365
6366 #define addToHash(c,b,h) if(h->find(c ## key) == h->end()) \
6367 {(*h)[c ## key]=true;} else { if ( c ## key != 0 ) b = false;}
6368 //Added an extra statement, so that if the key is cleared to 0, the cleared
6369 //keybinding status need not be unique. -Z ( 1st April, 2019 )
6370
6371 void load_ukeys(int32_t* arr)
6372 {
6373 arr[ukey_a] = Akey;
6374 arr[ukey_b] = Bkey;
6375 arr[ukey_s] = Skey;
6376 arr[ukey_l] = Lkey;
6377 arr[ukey_r] = Rkey;
6378 arr[ukey_p] = Pkey;
6379 arr[ukey_ex1] = Exkey1;
6380 arr[ukey_ex2] = Exkey2;
6381 arr[ukey_ex3] = Exkey3;
6382 arr[ukey_ex4] = Exkey4;
6383 arr[ukey_du] = DUkey;
6384 arr[ukey_dd] = DDkey;
6385 arr[ukey_dl] = DLkey;
6386 arr[ukey_dr] = DRkey;
6387 arr[ukey_mod1a] = cheat_modifier_keys[0];
6388 arr[ukey_mod1b] = cheat_modifier_keys[1];
6389 arr[ukey_mod2a] = cheat_modifier_keys[2];
6390 arr[ukey_mod2b] = cheat_modifier_keys[3];
6391 };
6392
6393 static const char* ukey_names[] = {
6394 "A", "B", "Start", "L", "R", "Map",
6395 "Ex1", "Ex2", "Ex3", "Ex4", "Up", "Down",
6396 "Left", "Right", "Cheat Mod L1", "Cheat Mod L2",
6397 "Cheat Mod R1", "Cheat Mod R2",
6398 };
6399 std::string get_ukey_name(int32_t k)
6400 {
6401 if (k < num_ukey) return ukey_names[k];
6402 return "";
6403 }
6404
6405 int32_t onKeyboard()
6406 {
6407 int32_t a = Akey;
6408 int32_t b = Bkey;
6409 int32_t s = Skey;
6410 int32_t l = Lkey;
6411 int32_t r = Rkey;
6412 int32_t p = Pkey;
6413 int32_t ex1 = Exkey1;
6414 int32_t ex2 = Exkey2;
6415 int32_t ex3 = Exkey3;
6416 int32_t ex4 = Exkey4;
6417 int32_t du = DUkey;
6418 int32_t dd = DDkey;
6419 int32_t dl = DLkey;
6420 int32_t dr = DRkey;
6421 int32_t mod1a = cheat_modifier_keys[0];
6422 int32_t mod1b = cheat_modifier_keys[1];
6423 int32_t mod2a = cheat_modifier_keys[2];
6424 int32_t mod2b = cheat_modifier_keys[3];
6425 bool done=false;
6426 int32_t ret;
6427
6428 keyboard_control_dlg[0].dp2=get_zc_font(font_lfont);
6429
6430 large_dialog(keyboard_control_dlg);
6431
6432 while(!done)
6433 {
6434 ret = do_zqdialog(keyboard_control_dlg,3);
6435
6436 if(ret==3) // OK
6437 {
6438 int32_t ukeys[num_ukey];
6439 load_ukeys(ukeys);
6440 std::vector<std::string> uniqueError;
6441 for(int32_t q = 0; q < num_ukey; ++q)
6442 {
6443 for(int32_t p = q+1; p < num_ukey; ++p)
6444 {
6445 if(ukeys[q] == ukeys[p] && ukeys[q] != 0)
6446 {
6447 char buf[64];
6448 sprintf(buf, "'%s' conflicts with '%s'", get_ukey_name(q).c_str(), get_ukey_name(p).c_str());
6449 std::string str(buf);
6450 uniqueError.push_back(str);
6451 }
6452 }
6453 }
6454 if(uniqueError.size() == 0)
6455 {
6456 done = true;
6457 save_control_configs(true);
6458 }
6459 else
6460 {
6461 box_start(1, "Duplicate Keys", get_zc_font(font_lfont), get_zc_font(font_sfont), false, keyboard_control_dlg[0].w,keyboard_control_dlg[0].h, 2);
6462 box_out("Cannot have duplicate keybinds!"); box_eol();
6463 for(std::vector<std::string>::iterator it = uniqueError.begin();
6464 it != uniqueError.end(); ++it)
6465 {
6466 box_out((*it).c_str()); box_eol();
6467 }
6468 box_end(true);
6469 }
6470 }
6471 else // Cancel
6472 {
6473 Akey = a;
6474 Bkey = b;
6475 Skey = s;
6476 Lkey = l;
6477 Rkey = r;
6478 Pkey = p;
6479 Exkey1 = ex1;
6480 Exkey2 = ex2;
6481 Exkey3 = ex3;
6482 Exkey4 = ex4;
6483 DUkey = du;
6484 DDkey = dd;
6485 DLkey = dl;
6486 DRkey = dr;
6487 cheat_modifier_keys[0] = mod1a;
6488 cheat_modifier_keys[1] = mod1b;
6489 cheat_modifier_keys[2] = mod2a;
6490 cheat_modifier_keys[3] = mod2b;
6491
6492 done=true;
6493 }
6494
6495 rest(1);
6496 }
6497
6498 return D_O_K;
6499 }
6500
6501 int32_t onGamepad()
6502 {
6503 if (al_get_num_joysticks() == 0)
6504 {
6505 InfoDialog("ZC", "No gamepads detected.").show();
6506 return D_O_K;
6507 }
6508
6509 int32_t a = Abtn;
6510 int32_t b = Bbtn;
6511 int32_t s = Sbtn;
6512 int32_t l = Lbtn;
6513 int32_t r = Rbtn;
6514 int32_t m = Mbtn;
6515 int32_t p = Pbtn;
6516 int32_t ex1 = Exbtn1;
6517 int32_t ex2 = Exbtn2;
6518 int32_t ex3 = Exbtn3;
6519 int32_t ex4 = Exbtn4;
6520 int32_t up = DUbtn;
6521 int32_t down = DDbtn;
6522 int32_t left = DLbtn;
6523 int32_t right = DRbtn;
6524 int32_t joy = joystick_index;
6525 int32_t stick_1 = js_stick_1_x_stick;
6526 int32_t stick_2 = js_stick_2_x_stick;
6527
6528 gamepad_dlg[0].dp2=get_zc_font(font_lfont);
6529 if(analog_movement)
6530 gamepad_dlg[56].flags|=D_SELECTED;
6531 else
6532 gamepad_dlg[56].flags&=~D_SELECTED;
6533
6534 // TODO: should use controller device GUID or name instead of index, otherwise this value is not
6535 // consistent unless exact same number of joysticks is always connected. Name is problematic b/c
6536 // xinput driver doesn't actually get a name (at least, doesn't for my Xbox controller).
6537 // TODO: should store gamepad control mappings per-controller, otherwise switching joystick
6538 // requires remapping every time.
6539 if (joystick_index >= al_get_num_joysticks())
6540 joystick_index = 0;
6541 gamepad_dlg[61].d2 = joystick_index;
6542
6543 gamepad_dlg_cur_joystick = al_get_joystick(joystick_index);
6544 if (!gamepad_dlg_cur_joystick)
6545 {
6546 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
6547 return D_CLOSE;
6548 }
6549
6550 large_dialog(gamepad_dlg);
6551
6552 int32_t ret = do_zqdialog(gamepad_dlg,4);
6553
6554 if(ret == 4) //OK
6555 {
6556 analog_movement = gamepad_dlg[56].flags&D_SELECTED;
6557 joystick_index = gamepad_dlg[61].d2;
6558 gamepad_dlg_cur_joystick = al_get_joystick(joystick_index);
6559 if (!gamepad_dlg_cur_joystick)
6560 {
6561 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
6562 return D_CLOSE;
6563 }
6564 js_stick_1_y_stick = js_stick_1_x_stick;
6565 js_stick_2_y_stick = js_stick_2_x_stick;
6566 save_control_configs(false);
6567 }
6568 else //Cancel
6569 {
6570 Abtn = a;
6571 Bbtn = b;
6572 Sbtn = s;
6573 Lbtn = l;
6574 Rbtn = r;
6575 Mbtn = m;
6576 Pbtn = p;
6577 Exbtn1 = ex1;
6578 Exbtn2 = ex2;
6579 Exbtn3 = ex3;
6580 Exbtn4 = ex4;
6581 DUbtn = up;
6582 DDbtn = down;
6583 DLbtn = left;
6584 DRbtn = right;
6585 joystick_index = joy;
6586 js_stick_1_x_stick = stick_1;
6587 js_stick_2_x_stick = stick_2;
6588 }
6589
6590 return D_O_K;
6591 }
6592
6593 int32_t onCheatKeys()
6594 {
6595 int32_t oldcheats[Cheat::Last][2];
6596 memcpy(oldcheats, cheatkeys, sizeof(cheatkeys));
6597
6598 bool done=false;
6599
6600 while(!done)
6601 {
6602 bool confirm = false;
6603 CheatKeysDialog(&confirm).show();
6604 if(confirm) // OK
6605 {
6606 std::vector<std::string> uniqueError;
6607 char buf[512];
6608 for(size_t q = 1; q < Cheat::Last; ++q)
6609 {
6610 if(cheatkeys[q][1] && !cheatkeys[q][0])
6611 {
6612 cheatkeys[q][0] = cheatkeys[q][1];
6613 cheatkeys[q][1] = 0;
6614 }
6615 }
6616 for(size_t q = 1; q < Cheat::Last; ++q)
6617 {
6618 if(!bindable_cheat((Cheat)q)) continue;
6619 for(size_t p = q+1; p < Cheat::Last; ++p)
6620 {
6621 if(!bindable_cheat((Cheat)p)) continue;
6622 for(size_t q2 = 0; q2 <= 1; ++q2)
6623 for(size_t p2 = 0; p2 <= 1; ++p2)
6624 {
6625 if(cheatkeys[q][q2] == cheatkeys[p][p2] && cheatkeys[q][q2] != 0)
6626 {
6627 uniqueError.push_back(fmt::format("'{}' ({}) conflicts with '{}' ({}) - both '{}'",
6628 cheat_to_string((Cheat)q), q2?"Alt":"Main",
6629 cheat_to_string((Cheat)p), p2?"Alt":"Main",
6630 get_keystr(cheatkeys[q][q2])));
6631 }
6632 }
6633 }
6634 }
6635 if(uniqueError.size() == 0)
6636 {
6637 done = true;
6638 save_cheatkeys();
6639 }
6640 else
6641 {
6642 box_start(1, "Duplicate Keys", get_zc_font(font_lfont), get_zc_font(font_sfont), false, 500,400, 2);
6643 box_out("Cannot have duplicate keybinds!"); box_eol();
6644 for(std::vector<std::string>::iterator it = uniqueError.begin();
6645 it != uniqueError.end(); ++it)
6646 {
6647 box_out((*it).c_str()); box_eol();
6648 }
6649 box_end(true);
6650 }
6651 }
6652 else // Cancel
6653 {
6654 memcpy(cheatkeys, oldcheats, sizeof(cheatkeys));
6655 done=true;
6656 }
6657 rest(1);
6658 }
6659
6660 return D_O_K;
6661 }
6662
6663 int32_t onSound()
6664 {
6665 if (get_qr(qr_OLD_SCRIPT_VOLUME))
6666 {
6667 if (FFCore.coreflags & FFCORE_SCRIPTED_MIDI_VOLUME)
6668 {
6669 master_volume(-1, ((int32_t)FFCore.usr_midi_volume));
6670 }
6671 if (FFCore.coreflags & FFCORE_SCRIPTED_DIGI_VOLUME)
6672 {
6673 master_volume((int32_t)(FFCore.usr_digi_volume), 1);
6674 }
6675 if (FFCore.coreflags & FFCORE_SCRIPTED_MUSIC_VOLUME)
6676 {
6677 emusic_volume = (int32_t)FFCore.usr_music_volume;
6678 }
6679 if (FFCore.coreflags & FFCORE_SCRIPTED_SFX_VOLUME)
6680 {
6681 sfx_volume = (int32_t)FFCore.usr_sfx_volume;
6682 }
6683 }
6684 if ( FFCore.coreflags&FFCORE_SCRIPTED_PANSTYLE )
6685 {
6686 pan_style = (int32_t)FFCore.usr_panstyle;
6687 }
6688
6689 int32_t m = midi_volume;
6690 int32_t e = emusic_volume;
6691 int32_t s = sfx_volume;
6692 int32_t p = pan_style;
6693 pan_style = vbound(pan_style,0,3);
6694
6695 sound_dlg[0].dp2=get_zc_font(font_lfont);
6696
6697 large_dialog(sound_dlg);
6698
6699 midi_dp[1] = sound_dlg[6].x;
6700 midi_dp[2] = sound_dlg[6].y;
6701 emus_dp[1] = sound_dlg[8].x;
6702 emus_dp[2] = sound_dlg[8].y;
6703 sfx_dp[1] = sound_dlg[10].x;
6704 sfx_dp[2] = sound_dlg[10].y;
6705 pan_dp[1] = sound_dlg[11].x;
6706 pan_dp[2] = sound_dlg[11].y;
6707 sound_dlg[15].d2 = (midi_volume==255) ? 32 : midi_volume>>3;
6708 sound_dlg[17].d2 = (emusic_volume==255) ? 32 : emusic_volume>>3;
6709 sound_dlg[19].d2 = (sfx_volume==255) ? 32 : sfx_volume>>3;
6710 sound_dlg[20].d2 = pan_style;
6711
6712 int32_t ret = do_zqdialog(sound_dlg,1);
6713
6714 if(ret==2)
6715 {
6716 master_volume(digi_volume,midi_volume);
6717 if (zcmusic)
6718 zcmusic_set_volume(zcmusic, emusic_volume);
6719
6720 int32_t temp_volume = sfx_volume;
6721 if (GameLoaded && !get_qr(qr_OLD_SCRIPT_VOLUME))
6722 temp_volume = (sfx_volume * FFCore.usr_sfx_volume) / 10000 / 100;
6723 for(int32_t i=0; i<WAV_COUNT; ++i)
6724 {
6725 if(sfx_voice[i] >= 0)
6726 voice_set_volume(sfx_voice[i], temp_volume);
6727 }
6728 zc_set_config(sfx_sect,"midi",midi_volume);
6729 zc_set_config(sfx_sect,"sfx",sfx_volume);
6730 zc_set_config(sfx_sect,"emusic",emusic_volume);
6731 zc_set_config(sfx_sect,"pan",pan_style);
6732 }
6733 else
6734 {
6735 midi_volume = m;
6736 emusic_volume = e;
6737 sfx_volume = s;
6738 pan_style = p;
6739 }
6740
6741 return D_O_K;
6742 }
6743
6744 int32_t queding(char const* s1, char const* s2, char const* s3)
6745 {
6746 return jwin_alert("ZQuest Classic",s1,s2,s3,"&Yes","&No",'y','n',get_zc_font(font_lfont));
6747 }
6748
6749 int32_t onQuit()
6750 {
6751 if(Playing)
6752 {
6753 int32_t ret=0;
6754
6755 if(get_qr(qr_NOCONTINUE))
6756 {
6757 if(standalone_mode)
6758 {
6759 ret=queding("End current game?",
6760 "The continue screen is disabled; the game",
6761 "will be reloaded from the last save.");
6762 }
6763 else
6764 {
6765 ret=queding("End current game?",
6766 "The continue screen is disabled. You will",
6767 "be returned to the file select screen.");
6768 }
6769 }
6770 else
6771 ret=queding("End current game?",NULL,NULL);
6772
6773 if(ret==1)
6774 {
6775 disableClickToFreeze=false;
6776 Quit=qQUIT;
6777
6778 // Trying to evade a door repair charge?
6779 if(repaircharge)
6780 {
6781 game->change_drupy(-repaircharge);
6782 repaircharge=0;
6783 }
6784
6785 return D_CLOSE;
6786 }
6787 }
6788
6789 return D_O_K;
6790 }
6791
6792 int32_t onTryQuitMenu()
6793 {
6794 return onTryQuit(true);
6795 }
6796
6797 int32_t onTryQuit(bool inMenu)
6798 {
6799 if(Playing && !(GameFlags & GAMEFLAG_NO_F6))
6800 {
6801 if(active_cutscene.can_f6())
6802 {
6803 if(get_qr(qr_OLD_F6))
6804 {
6805 if(inMenu) onQuit();
6806 else /*if(!get_qr(qr_NOCONTINUE))*/ f_Quit(qQUIT);
6807 }
6808 else
6809 {
6810 disableClickToFreeze=false;
6811 GameFlags |= GAMEFLAG_TRYQUIT;
6812 }
6813 return D_CLOSE;
6814 }
6815 else active_cutscene.error();
6816 }
6817
6818 return D_O_K;
6819 }
6820
6821 int32_t onReset()
6822 {
6823 if(queding(" Reset system? ",NULL,NULL)==1)
6824 {
6825 disableClickToFreeze=false;
6826 Quit=qRESET;
6827 replay_quit();
6828 return D_CLOSE;
6829 }
6830
6831 return D_O_K;
6832 }
6833
6834 int32_t onExit()
6835 {
6836 if(queding(" Quit ZQuest Classic? ",NULL,NULL)==1)
6837 {
6838 Quit=qEXIT;
6839 return D_CLOSE;
6840 }
6841
6842 return D_O_K;
6843 }
6844
6845 int32_t onDebug()
6846 {
6847 if(debug_enabled)
6848 set_debug(!get_debug());
6849 return D_O_K;
6850 }
6851
6852 int32_t onHeartBeep()
6853 {
6854 heart_beep=!heart_beep;
6855 zc_set_config(cfg_sect,"heart_beep",heart_beep);
6856 return D_O_K;
6857 }
6858
6859 int32_t onSaveIndicator()
6860 {
6861 use_save_indicator = use_save_indicator ? 0 : 1;
6862 zc_set_config(cfg_sect,"save_indicator",use_save_indicator);
6863 return D_O_K;
6864 }
6865
6866 int32_t onEpilepsy()
6867 {
6868 if(jwin_alert3(
6869 "Epilepsy Flash Reduction",
6870 "Enabling this will reduce the intensity of flashing and screen wave effects.",
6871 "Disabling this will restore standard flash and wavy behaviour.",
6872 "Proceed?",
6873 "&Yes",
6874 "&No",
6875 NULL,
6876 'y',
6877 'n',
6878 0,
6879 get_zc_font(font_lfont)) == 1)
6880 {
6881 epilepsyFlashReduction = epilepsyFlashReduction ? 0 : 1;
6882 zc_set_config(cfg_sect,"epilepsy_flash_reduction",epilepsyFlashReduction);
6883 }
6884 return D_O_K;
6885 }
6886
6887 bool rc = false;
6888
6889 static DIALOG getnum_dlg[] =
6890 {
6891 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
6892 { jwin_win_proc, 80, 80, 160, 72, vc(0), vc(11), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
6893 { jwin_text_proc, 104, 104+4, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Number:", NULL, NULL },
6894 { jwin_edit_proc, 168, 104, 48, 16, 0, 0, 0, 0, 6, 0, NULL, NULL, NULL },
6895 { jwin_button_proc, 90, 126, 61, 21, vc(0), vc(11), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6896 { jwin_button_proc, 170, 126, 61, 21, vc(0), vc(11), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
6897 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6898 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6899 };
6900
6901 int32_t getnumber(const char *prompt,int32_t initialval)
6902 {
6903 char buf[20];
6904 sprintf(buf,"%d",initialval);
6905 getnum_dlg[0].dp=(void *)prompt;
6906 getnum_dlg[0].dp2=get_zc_font(font_lfont);
6907 getnum_dlg[2].dp=buf;
6908
6909 large_dialog(getnum_dlg);
6910
6911 if(do_zqdialog(getnum_dlg,2)==3)
6912 return atoi(buf);
6913
6914 return initialval;
6915 }
6916
6917 int32_t onLife()
6918 {
6919 int value = vbound(getnumber("Life",game->get_life()),1,game->get_maxlife());
6920 cheats_enqueue(Cheat::Life, value);
6921 return D_O_K;
6922 }
6923
6924 int32_t onHeartC()
6925 {
6926 int max_life = vbound(getnumber("Heart Containers",game->get_maxlife()/game->get_hp_per_heart()),1,4095) * game->get_hp_per_heart();
6927 int life = vbound(getnumber("Life",game->get_life()/game->get_hp_per_heart()),1,max_life/game->get_hp_per_heart())*game->get_hp_per_heart();
6928 cheats_enqueue(Cheat::MaxLife, max_life);
6929 cheats_enqueue(Cheat::Life, life);
6930 return D_O_K;
6931 }
6932
6933 int32_t onMagicC()
6934 {
6935 int max_magic = vbound(getnumber("Magic Containers",game->get_maxmagic()/game->get_mp_per_block()),0,2047) * game->get_mp_per_block();
6936 int magic = vbound(getnumber("Magic",game->get_magic()/game->get_mp_per_block()),0,max_magic/game->get_mp_per_block())*game->get_mp_per_block();
6937 cheats_enqueue(Cheat::MaxMagic, max_magic);
6938 cheats_enqueue(Cheat::Magic, magic);
6939 return D_O_K;
6940 }
6941
6942 int32_t onRupies()
6943 {
6944 int value = vbound(getnumber("Rupees",game->get_rupies()),0,game->get_maxcounter(1));
6945 cheats_enqueue(Cheat::Rupies, value);
6946 return D_O_K;
6947 }
6948
6949 int32_t onMaxBombs()
6950 {
6951 int value = vbound(getnumber("Max Bombs",game->get_maxbombs()),0,0xFFFF);
6952 cheats_enqueue(Cheat::MaxBombs, value);
6953 cheats_enqueue(Cheat::Bombs, value);
6954 return D_O_K;
6955 }
6956
6957 int32_t onRefillLife()
6958 {
6959 cheats_enqueue(Cheat::Life, game->get_maxlife());
6960 return D_O_K;
6961 }
6962 int32_t onRefillMagic()
6963 {
6964 cheats_enqueue(Cheat::Magic, game->get_maxmagic());
6965 return D_O_K;
6966 }
6967 int32_t onClock()
6968 {
6969 cheats_enqueue(Cheat::Clock);
6970 return D_O_K;
6971 }
6972
6973 int32_t onQstPath()
6974 {
6975 char initial_path[2048];
6976 chop_path(qstdir);
6977 strcpy(initial_path, qstdir);
6978
6979 if (auto result = prompt_for_existing_folder("Quest File Directory", initial_path, "qst"))
6980 {
6981 char* path = result->data();
6982 chop_path(path);
6983 fix_filename_case(path);
6984 fix_filename_slashes(path);
6985 strcpy(qstdir,path);
6986 strcpy(qstpath,qstdir);
6987 zc_set_config("zeldadx","quest_dir",qstdir);
6988 flush_config_file();
6989 }
6990
6991 return D_O_K;
6992 }
6993
6994 #include "dialog/cheat_dialog.h"
6995 int32_t onCheat()
6996 {
6997 call_setcheat_dialog();
6998 game->set_cheat(maxcheat);
6999 if(cheat) game->did_cheat(true);
7000 return D_O_K;
7001 }
7002
7003 int32_t onCheatRupies()
7004 {
7005 cheats_enqueue(Cheat::Rupies, game->get_maxcounter(1));
7006 return D_O_K;
7007 }
7008
7009 int32_t onCheatArrows()
7010 {
7011 cheats_enqueue(Cheat::Arrows, game->get_maxarrows());
7012 return D_O_K;
7013 }
7014
7015 int32_t onCheatBombs()
7016 {
7017 cheats_enqueue(Cheat::Bombs, game->get_maxbombs(), game->get_maxcounter(6));
7018 return D_O_K;
7019 }
7020
7021 // *** screen saver
7022
7023 18303615 int32_t after_time()
7024 {
7025
1/2
✓ Branch 0 taken 18303615 times.
✗ Branch 1 not taken.
18303615 if(ss_enable == 0)
7026 return INT_MAX;
7027
7028
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18303615 times.
18303615 if(ss_after <= 0)
7029 return 5 * 60;
7030
7031
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18303615 times.
18303615 if(ss_after <= 3)
7032 return ss_after * 15 * 60;
7033
7034
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18303615 times.
18303615 if(ss_after <= 13)
7035 return (ss_after - 3) * 60 * 60;
7036
7037 18303615 return MAX_IDLE + 1;
7038 18303615 }
7039
7040 static const char *after_str[15] =
7041 {
7042 " 5 sec", "15 sec", "30 sec", "45 sec", " 1 min", " 2 min", " 3 min",
7043 " 4 min", " 5 min", " 6 min", " 7 min", " 8 min", " 9 min", "10 min",
7044 "Never"
7045 };
7046
7047 const char *after_list(int32_t index, int32_t *list_size)
7048 {
7049 if(index < 0)
7050 {
7051 *list_size = 15;
7052 return NULL;
7053 }
7054
7055 return after_str[index];
7056 }
7057
7058 329 static ListData after__list(after_list, &font);
7059
7060 static DIALOG scrsaver_dlg[] =
7061 {
7062 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
7063 329 { jwin_win_proc, 32, 64, 256, 136, 0, 0, 0, D_EXIT, 0, 0, (void *) "Screen Saver Settings", NULL, NULL },
7064 329 { jwin_frame_proc, 42, 92, 236, 70, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
7065 329 { jwin_text_proc, 60, 104, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Run After", NULL, NULL },
7066 329 { jwin_text_proc, 60, 128, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Speed", NULL, NULL },
7067 329 { jwin_text_proc, 60, 144, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Density", NULL, NULL },
7068 329 { jwin_droplist_proc, 144, 100, 96, 16, 0, 0, 0, 0, 0, 0, (void *) &after__list, NULL, NULL },
7069 329 { jwin_slider_proc, 144, 128, 116, 8, vc(0), jwin_pal[jcBOX], 0, 0, 6, 0, NULL, NULL, NULL },
7070 329 { jwin_slider_proc, 144, 144, 116, 8, vc(0), jwin_pal[jcBOX], 0, 0, 6, 0, NULL, NULL, NULL },
7071 329 { jwin_button_proc, 42, 170, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
7072 329 { jwin_button_proc, 124, 170, 72, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Preview", NULL, NULL },
7073 329 { jwin_button_proc, 218, 170, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
7074 329 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
7075 329 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
7076 };
7077
7078 int32_t onScreenSaver()
7079 {
7080 scrsaver_dlg[0].dp2=get_zc_font(font_lfont);
7081 int32_t oldcfgs[3];
7082 scrsaver_dlg[5].d1 = scrsaver_dlg[5].d2 = oldcfgs[0] = ss_after;
7083 scrsaver_dlg[6].d2 = oldcfgs[1] = ss_speed;
7084 scrsaver_dlg[7].d2 = oldcfgs[2] = ss_density;
7085
7086 large_dialog(scrsaver_dlg);
7087
7088 int32_t ret = do_zqdialog(scrsaver_dlg,-1);
7089
7090 if(ret == 8 || ret == 9)
7091 {
7092 ss_after = scrsaver_dlg[5].d1;
7093 ss_speed = scrsaver_dlg[6].d2;
7094 ss_density = scrsaver_dlg[7].d2;
7095 if(oldcfgs[0] != ss_after)
7096 zc_set_config(cfg_sect,"ss_after",ss_after);
7097 if(oldcfgs[1] != ss_speed)
7098 zc_set_config(cfg_sect,"ss_speed",ss_speed);
7099 if(oldcfgs[2] != ss_density)
7100 zc_set_config(cfg_sect,"ss_density",ss_density);
7101 }
7102
7103 if(ret == 9)
7104 // preview Screen Saver
7105 {
7106 clear_keybuf();
7107 Matrix(ss_speed, ss_density, 30);
7108 system_pal(true);
7109 sys_mouse();
7110 }
7111
7112 return D_O_K;
7113 }
7114
7115 /***** Menus *****/
7116
7117 enum
7118 {
7119 MENUID_GAME_LOADQUEST,
7120 MENUID_GAME_ENDGAME,
7121 };
7122
1/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
329 static NewMenu game_menu
7123 2632 {
7124
3/6
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 329 times.
✗ Branch 5 not taken.
329 { "&Continue","ESC", onContinue },
7125
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 {},
7126
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "L&oad Quest...", onCustomGame, MENUID_GAME_LOADQUEST },
7127
3/6
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 329 times.
✗ Branch 5 not taken.
329 { "&End Game","F6", onTryQuitMenu, MENUID_GAME_ENDGAME },
7128
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 {},
7129 #ifdef __EMSCRIPTEN__
7130 { "&Reset","F7", onReset },
7131 #elif defined(ALLEGRO_MACOSX)
7132 { "&Reset","F7", onReset },
7133 { "&Quit","F8", onExit },
7134 #else
7135
3/6
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 329 times.
✗ Branch 5 not taken.
329 { "&Reset","F9", onReset },
7136
3/6
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 329 times.
✗ Branch 5 not taken.
329 { "&Quit","F10", onExit },
7137 #endif
7138 };
7139
7140
1/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
329 static NewMenu snapshot_format_menu
7141 2303 {
7142
4/8
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 329 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 329 times.
✗ Branch 7 not taken.
329 { "&BMP", std::bind(onSetSnapshotFormat, ssfmtBMP) },
7143
4/8
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 329 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 329 times.
✗ Branch 7 not taken.
329 { "&GIF", std::bind(onSetSnapshotFormat, ssfmtGIF) },
7144
4/8
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 329 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 329 times.
✗ Branch 7 not taken.
329 { "&JPG", std::bind(onSetSnapshotFormat, ssfmtJPG) },
7145
4/8
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 329 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 329 times.
✗ Branch 7 not taken.
329 { "&PNG", std::bind(onSetSnapshotFormat, ssfmtPNG) },
7146
4/8
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 329 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 329 times.
✗ Branch 7 not taken.
329 { "PC&X", std::bind(onSetSnapshotFormat, ssfmtPCX) },
7147
4/8
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 329 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 329 times.
✗ Branch 7 not taken.
329 { "&TGA", std::bind(onSetSnapshotFormat, ssfmtTGA) },
7148 };
7149
7150
1/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
329 static NewMenu controls_menu
7151 1316 {
7152
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Key&board...", onKeyboard },
7153
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "&Gamepad...", onGamepad },
7154
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "&Cheat Keys...", onCheatKeys },
7155 };
7156
7157
1/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
329 static NewMenu name_entry_mode_menu
7158 1316 {
7159
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "&Keyboard", onKeyboardEntry },
7160
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "&Letter Grid", onLetterGridEntry },
7161
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "&Extended Letter Grid", onExtLetterGridEntry },
7162 };
7163
7164 static void set_controls_menu_active()
7165 {
7166
7167 }
7168
7169 enum
7170 {
7171 MENUID_WINDOW_LOCK_ASPECT,
7172 MENUID_WINDOW_LOCK_INTSCALE,
7173 MENUID_WINDOW_SAVE_SIZE,
7174 MENUID_WINDOW_SAVE_POS,
7175 MENUID_WINDOW_STRETCH,
7176 };
7177
1/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
329 static NewMenu window_menu
7178 1974 {
7179
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Lock Aspect Ratio", onDragAspect, MENUID_WINDOW_LOCK_ASPECT },
7180
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Lock Integer Scale", onIntegerScaling, MENUID_WINDOW_LOCK_INTSCALE },
7181
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Save Size Changes", onSaveDragResize, MENUID_WINDOW_SAVE_SIZE },
7182
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Save Position Changes", onWinPosSave, MENUID_WINDOW_SAVE_POS },
7183
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Stretch Game Area", onStretchGame, MENUID_WINDOW_STRETCH },
7184 };
7185 void call_zc_options_dlg();
7186 enum
7187 {
7188 MENUID_OPTIONS_PAUSE_BG,
7189 MENUID_OPTIONS_EPILEPSYPROT,
7190 };
7191
1/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
329 static NewMenu options_menu
7192 2303 {
7193
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Name &Entry Mode", &name_entry_mode_menu },
7194
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "S&napshot Format", &snapshot_format_menu },
7195
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "&Window Settings", &window_menu },
7196
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Epilepsy Flash Reduction", onEpilepsy, MENUID_OPTIONS_EPILEPSYPROT },
7197
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Pause In Background", onPauseInBackground, MENUID_OPTIONS_PAUSE_BG },
7198
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "More Options", call_zc_options_dlg },
7199 };
7200 enum
7201 {
7202 MENUID_SETTINGS_CONTROLS,
7203 MENUID_SETTINGS_CAPFPS,
7204 MENUID_SETTINGS_SHOWFPS,
7205 MENUID_SETTINGS_SHOWTIME,
7206 MENUID_SETTINGS_CLICK_FREEZE,
7207 MENUID_SETTINGS_TRANSLAYERS,
7208 MENUID_SETTINGS_NESQUIT,
7209 MENUID_SETTINGS_VOLKEYS,
7210 MENUID_SETTINGS_HEARTBEEP,
7211 MENUID_SETTINGS_SAVEINDICATOR,
7212 MENUID_SETTINGS_DEBUG,
7213 };
7214
1/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
329 static NewMenu settings_menu
7215 5593 {
7216
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "&Sound...", onSound },
7217
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "C&ontrols", &controls_menu, MENUID_SETTINGS_CONTROLS },
7218
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 {},
7219
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Options", &options_menu },
7220
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 {},
7221
3/6
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 329 times.
✗ Branch 5 not taken.
329 { "&Cap FPS","F1", onThrottleFPS, MENUID_SETTINGS_CAPFPS },
7222
3/6
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 329 times.
✗ Branch 5 not taken.
329 { "Show &FPS","F2", onShowFPS, MENUID_SETTINGS_SHOWFPS },
7223
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Show &Time", onShowTime, MENUID_SETTINGS_SHOWTIME },
7224
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Click to Freeze", onClickToFreeze, MENUID_SETTINGS_CLICK_FREEZE },
7225
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Cont. &Heart Beep", onHeartBeep, MENUID_SETTINGS_HEARTBEEP },
7226
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Show Trans. &Layers", onTransLayers, MENUID_SETTINGS_TRANSLAYERS },
7227
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Up+A+B To &Quit", onNESquit, MENUID_SETTINGS_NESQUIT },
7228
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Volume &Keys", onVolKeys, MENUID_SETTINGS_VOLKEYS },
7229
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Sa&ve Indicator", onSaveIndicator, MENUID_SETTINGS_SAVEINDICATOR },
7230
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 {},
7231
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Debu&g", onDebug, MENUID_SETTINGS_DEBUG },
7232 };
7233
7234 enum
7235 {
7236 MENUID_MISC_FULLSCREEN,
7237 MENUID_MISC_VIDMODE,
7238 MENUID_MISC_QUEST_INFO,
7239 MENUID_MISC_QUEST_DIR,
7240 MENUID_MISC_CONSOLE,
7241 MENUID_MISC_CLEAR_CONSOLE_ON_LOAD,
7242 };
7243
1/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
329 static NewMenu misc_menu
7244 4935 {
7245
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "&About...", onAbout },
7246 // TODO: re-enable, but: 1) do not use a bitmap thing that is hard to update 2) update names and 3) don't use the Z-word.
7247 // { "&Credits...", onCredits },
7248
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "&Fullscreen", onFullscreenMenu, MENUID_MISC_FULLSCREEN },
7249
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "&Video Mode...", onVidMode, MENUID_MISC_VIDMODE },
7250
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 {},
7251
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "&Quest Info...", onQuest, MENUID_MISC_QUEST_INFO },
7252
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Quest &MIDI Info...", onMIDICredits },
7253
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Quest &Directory...", onQstPath, MENUID_MISC_QUEST_DIR },
7254
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 {},
7255
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Take &Snapshot F12", onSnapshot },
7256
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Sc&reen Saver...", onScreenSaver },
7257
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Save ZC Configuration", OnSaveZCConfig },
7258
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Show Console", onConsole, MENUID_MISC_CONSOLE },
7259
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Clear Console on Qst Load", onClrConsoleOnLoad, MENUID_MISC_CLEAR_CONSOLE_ON_LOAD },
7260
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Clear Directory Cache", OnnClearQuestDir },
7261 };
7262
7263 enum
7264 {
7265 MENUID_REFILL_ARROWS,
7266 };
7267
1/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
329 static NewMenu refill_menu
7268 1974 {
7269
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "&Life", onRefillLife },
7270
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "&Magic", onRefillMagic },
7271
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "&Bombs", onCheatBombs },
7272
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "&Rupees", onCheatRupies },
7273
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "&Arrows", onCheatArrows, MENUID_REFILL_ARROWS },
7274 };
7275
7276 enum
7277 {
7278 MENUID_SHOW_L0,
7279 MENUID_SHOW_L1,
7280 MENUID_SHOW_L2,
7281 MENUID_SHOW_L3,
7282 MENUID_SHOW_L4,
7283 MENUID_SHOW_L5,
7284 MENUID_SHOW_L6,
7285 MENUID_SHOW_OVER,
7286 MENUID_SHOW_PUSH,
7287 MENUID_SHOW_FFC,
7288 MENUID_SHOW_SPR,
7289 MENUID_SHOW_SCRIPTNAME,
7290 MENUID_SHOW_SOLIDITY,
7291 MENUID_SHOW_HITBOX,
7292 MENUID_SHOW_EFFECT,
7293 };
7294
1/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
329 static NewMenu show_menu
7295 6251 {
7296
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Combos", onShowLayer0, MENUID_SHOW_L0 },
7297
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Layer 1", onShowLayer1, MENUID_SHOW_L1 },
7298
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Layer 2", onShowLayer2, MENUID_SHOW_L2 },
7299
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Layer 3", onShowLayer3, MENUID_SHOW_L3 },
7300
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Layer 4", onShowLayer4, MENUID_SHOW_L4 },
7301
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Layer 5", onShowLayer5, MENUID_SHOW_L5 },
7302
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Layer 6", onShowLayer6, MENUID_SHOW_L6 },
7303
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Overhead Combos", onShowLayerO, MENUID_SHOW_OVER },
7304
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Push Blocks", onShowLayerP, MENUID_SHOW_PUSH },
7305
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Freeform Combos", onShowLayerF, MENUID_SHOW_FFC },
7306
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Sprites", onShowLayerS, MENUID_SHOW_SPR },
7307
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 {},
7308
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Current FFC Scripts", onShowFFScripts, MENUID_SHOW_SCRIPTNAME },
7309
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 {},
7310
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Walkability", onShowLayerW, MENUID_SHOW_SOLIDITY },
7311
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Hitboxes", onShowHitboxes, MENUID_SHOW_HITBOX },
7312
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Effects", onShowLayerE, MENUID_SHOW_EFFECT },
7313
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Info Opacity", onShowInfoOpacity },
7314 };
7315
7316 enum
7317 {
7318 MENUID_CHEAT_CHOP_L1,
7319 MENUID_CHEAT_CHOP_L2,
7320 MENUID_CHEAT_CHOP_L3,
7321 MENUID_CHEAT_CHOP_L4,
7322 MENUID_CHEAT_INVULN,
7323 MENUID_CHEAT_NOCLIP,
7324 MENUID_CHEAT_IGNORESV,
7325 MENUID_CHEAT_GOFAST,
7326 };
7327
1/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
329 static NewMenu cheat_menu
7328 5593 {
7329
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Set &Cheat", onCheat },
7330
1/2
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
329 { MENUID_CHEAT_CHOP_L1 },
7331
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Re&fill", &refill_menu },
7332
1/2
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
329 { MENUID_CHEAT_CHOP_L2 },
7333
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "&Invincible", onClock, MENUID_CHEAT_INVULN },
7334
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Ma&x Bombs...", onMaxBombs },
7335
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "&Heart Containers...", onHeartC },
7336
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "&Magic Containers...", onMagicC },
7337
1/2
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
329 { MENUID_CHEAT_CHOP_L3 },
7338
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "&Player Data...", onCheatConsole },
7339
1/2
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
329 { MENUID_CHEAT_CHOP_L4 },
7340
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Walk Through &Walls", onNoWalls, MENUID_CHEAT_NOCLIP },
7341
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Player Ignores Side&view", onIgnoreSideview, MENUID_CHEAT_IGNORESV },
7342
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "&Quick Movement", onGoFast, MENUID_CHEAT_GOFAST },
7343
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "&Kill All Enemies", onKillCheat },
7344
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Trigger &Secrets", onSecretsCheat },
7345
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Trigger Secrets Perm", onSecretsCheatPerm },
7346
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Show/Hide Layer", &show_menu },
7347
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "Toggle &Light", onLightSwitch },
7348
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "&Goto Location...", onGoTo },
7349 };
7350
7351 #if DEVLEVEL > 0
7352 int32_t devLogging();
7353 int32_t devDebug();
7354 int32_t devTimestmp();
7355 #if DEVLEVEL > 1
7356 int32_t setCheat();
7357 #endif //DEVLEVEL > 1
7358 enum
7359 {
7360 MENUID_DEV_LOGGING,
7361 MENUID_DEV_DEBUG,
7362 MENUID_DEV_TIMESTAMP,
7363 MENUID_DEV_SETCHEAT,
7364 };
7365 static NewMenu dev_menu
7366 {
7367 { "&Force Error Log", devLogging, MENUID_DEV_LOGGING },
7368 // { "&Extra Debug Log", devDebug, MENUID_DEV_DEBUG },
7369 { "&Timestamp Log", devTimestmp, MENUID_DEV_TIMESTAMP },
7370 #if DEVLEVEL > 1
7371 {},
7372 { "Set &Cheat", setCheat, MENUID_DEV_SETCHEAT },
7373 #endif //DEVLEVEL > 1
7374 };
7375 int32_t devLogging()
7376 {
7377 dev_logging = !dev_logging;
7378 dev_menu.select_uid(MENUID_DEV_LOGGING, dev_logging);
7379 return D_O_K;
7380 }
7381 // int32_t devDebug()
7382 // {
7383 // dev_debug = !dev_debug;
7384 // dev_menu.select_uid(MENUID_DEV_DEBUG, dev_debug);
7385 // dev_menu[dv_dbg].flags = dev_debug ? D_SELECTED : 0;
7386 // return D_O_K;
7387 // }
7388 int32_t devTimestmp()
7389 {
7390 dev_timestmp = !dev_timestmp;
7391 dev_menu.select_uid(MENUID_DEV_TIMESTAMP, dev_timestmp);
7392 return D_O_K;
7393 }
7394 #if DEVLEVEL > 1
7395 int32_t setCheat()
7396 {
7397 cheat = (vbound(getnumber("Cheat Level",cheat), 0, 4));
7398 return D_O_K;
7399 }
7400 #endif //DEVLEVEL > 1
7401 #endif //DEVLEVEL > 0
7402
7403 enum
7404 {
7405 MENUID_PLAYER_CHEAT,
7406 };
7407
1/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
329 TopMenu the_player_menu
7408 1974 {
7409
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "&Game", &game_menu },
7410
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "&Settings", &settings_menu },
7411
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "&Cheat", &cheat_menu, MENUID_PLAYER_CHEAT, true },
7412
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "&Replay", &replay_menu },
7413
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 { "&ZC", &misc_menu },
7414 #if DEVLEVEL > 0
7415 { "&Dev", &dev_menu },
7416 #endif
7417 };
7418
7419 int32_t onPauseInBackground()
7420 {
7421 if(jwin_alert3(
7422 "Toggle Pause In Background",
7423 "This action will change whether ZC Player pauses when the window loses focus.",
7424 "",
7425 "Proceed?",
7426 "&Yes",
7427 "&No",
7428 NULL,
7429 'y',
7430 'n',
7431 0,
7432 get_zc_font(font_lfont)) == 1)
7433 {
7434 pause_in_background = pause_in_background ? 0 : 1;
7435 zc_set_config("zeldadx","pause_in_background", pause_in_background);
7436 int switch_type = pause_in_background ? SWITCH_PAUSE : SWITCH_BACKGROUND;
7437 set_display_switch_mode(fullscreen?SWITCH_BACKAMNESIA:switch_type);
7438 set_display_switch_callback(SWITCH_OUT, switch_out_callback);
7439 set_display_switch_callback(SWITCH_IN, switch_in_callback);
7440 }
7441 options_menu.select_uid(MENUID_OPTIONS_PAUSE_BG, pause_in_background);
7442 return D_O_K;
7443 }
7444
7445 int32_t onKeyboardEntry()
7446 {
7447 NameEntryMode=0;
7448 zc_set_config(cfg_sect,"name_entry_mode",NameEntryMode);
7449 return D_O_K;
7450 }
7451
7452 int32_t onLetterGridEntry()
7453 {
7454 NameEntryMode=1;
7455 zc_set_config(cfg_sect,"name_entry_mode",NameEntryMode);
7456 return D_O_K;
7457 }
7458
7459 int32_t onExtLetterGridEntry()
7460 {
7461 NameEntryMode=2;
7462 zc_set_config(cfg_sect,"name_entry_mode",NameEntryMode);
7463 return D_O_K;
7464 }
7465
7466 static BITMAP* oldscreen;
7467 int32_t onFullscreenMenu()
7468 {
7469 PALETTE oldpal;
7470 get_palette(oldpal);
7471
7472 fullscreen = !fullscreen;
7473 all_toggle_fullscreen(fullscreen);
7474 zc_set_config("zeldadx","fullscreen",fullscreen);
7475
7476 zc_set_palette(oldpal);
7477 gui_mouse_focus=0;
7478 extern int32_t switch_type;
7479 switch_type = pause_in_background ? SWITCH_PAUSE : SWITCH_BACKGROUND;
7480 set_display_switch_mode(fullscreen?SWITCH_BACKAMNESIA:switch_type);
7481 set_display_switch_callback(SWITCH_OUT, switch_out_callback);
7482 set_display_switch_callback(SWITCH_IN, switch_in_callback);
7483 misc_menu.select_uid(MENUID_MISC_FULLSCREEN, isFullScreen());
7484 misc_menu.select_uid(MENUID_MISC_VIDMODE, isFullScreen());
7485
7486 return D_O_K;
7487 }
7488
7489 239 void fix_menu()
7490 {
7491
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 239 times.
239 if(!debug_enabled)
7492 239 settings_menu.chop_index = 13;
7493 239 }
7494
7495 int32_t onSetSnapshotFormat(SnapshotType format)
7496 {
7497 SnapshotFormat = format;
7498 zc_set_config("zeldadx", "snapshot_format", format);
7499 snapshot_format_menu.select_only_index(format);
7500 return D_O_K;
7501 }
7502
7503
7504 void color_layer(RGB *src,RGB *dest,char r,char g,char b,char pos,int32_t from,int32_t to)
7505 {
7506 PALETTE tmp;
7507
7508 for(int32_t i=0; i<256; i++)
7509 {
7510 tmp[i].r=r;
7511 tmp[i].g=g;
7512 tmp[i].b=b;
7513 }
7514
7515 fade_interpolate(src,tmp,dest,pos,from,to);
7516 }
7517
7518 55 void system_pal(bool force)
7519 {
7520
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 55 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
55 if(is_sys_pal && !force) return;
7521 55 is_sys_pal = true;
7522 55 load_colorset(gui_colorset, syspal, jwin_a5_colors);
7523 55 hw_palette = &syspal;
7524 55 update_hw_pal = true;
7525 55 }
7526
7527 static uint32_t entered_sys_pal = 0;
7528 55 void enter_sys_pal()
7529 {
7530
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55 times.
55 if(is_sys_pal)
7531 {
7532 if(entered_sys_pal)
7533 ++entered_sys_pal;
7534 return;
7535 }
7536 55 sys_mouse();
7537 55 system_pal(true);
7538 55 ++entered_sys_pal;
7539 55 }
7540 55 void exit_sys_pal()
7541 {
7542
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55 times.
55 if(entered_sys_pal)
7543 {
7544
1/2
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
55 if(!--entered_sys_pal)
7545 {
7546 55 game_pal();
7547 55 game_mouse();
7548 55 }
7549 55 }
7550 55 }
7551
7552 void switch_out_callback()
7553 {
7554 if (pause_in_background && !MenuOpen)
7555 {
7556 System();
7557 }
7558 }
7559
7560 void switch_in_callback()
7561 {
7562 }
7563
7564 1073 void game_pal()
7565 {
7566 1073 is_sys_pal = false;
7567 1073 entered_sys_pal = 0;
7568 1073 hw_palette = &RAMpal;
7569 1073 update_hw_pal = true;
7570 1073 }
7571
7572 static char bar_str[] = "";
7573
7574 55 void music_pause()
7575 {
7576 //al_pause_duh(tmplayer);
7577 55 zcmusic_pause(zcmusic, ZCM_PAUSE);
7578
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55 times.
55 if(zcmixer->oldtrack)
7579 zcmusic_pause(zcmixer->oldtrack, ZCM_PAUSE);
7580 55 zc_midi_pause();
7581 55 }
7582
7583 void music_resume()
7584 {
7585 //al_resume_duh(tmplayer);
7586 zcmusic_pause(zcmusic, ZCM_RESUME);
7587 if (zcmixer->oldtrack)
7588 zcmusic_pause(zcmixer->oldtrack, ZCM_RESUME);
7589 zc_midi_resume();
7590 }
7591
7592 7739 void music_stop()
7593 {
7594 //al_stop_duh(tmplayer);
7595 //unload_duh(tmusic);
7596 //tmusic=NULL;
7597 //tmplayer=NULL;
7598 7739 zcmusic_stop(zcmusic);
7599 7739 zcmusic_unload_file(zcmusic);
7600
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7739 times.
7739 if (zcmixer->oldtrack)
7601 {
7602 zcmusic_stop(zcmixer->oldtrack);
7603 zcmusic_unload_file(zcmixer->oldtrack);
7604 }
7605 7739 zcmixer->newtrack = NULL;
7606 7739 zc_stop_midi();
7607 7739 currmidi=-1;
7608 7739 }
7609
7610 bool reload_fonts = false;
7611 void System()
7612 {
7613 mouse_down = gui_mouse_b();
7614 music_pause();
7615 pause_all_sfx();
7616 MenuOpen = true;
7617 enter_sys_pal();
7618 // FONT *oldfont=font;
7619 // font=tfont;
7620
7621 misc_menu.select_uid(MENUID_MISC_FULLSCREEN, isFullScreen());
7622 misc_menu.disable_uid(MENUID_MISC_VIDMODE, isFullScreen());
7623
7624 #if DEVLEVEL > 1
7625 dev_menu.disable_uid(MENUID_DEV_SETCHEAT, !Playing);
7626 #endif
7627 game_menu.disable_uid(MENUID_GAME_LOADQUEST, getsaveslot() < 0);
7628 game_menu.disable_uid(MENUID_GAME_ENDGAME, !Playing);
7629 misc_menu.disable_uid(MENUID_MISC_QUEST_INFO, !Playing);
7630 misc_menu.disable_uid(MENUID_MISC_QUEST_DIR, Playing);
7631 clear_keybuf();
7632
7633 clear_bitmap(menu_bmp);
7634 oldscreen = screen;
7635 screen = menu_bmp;
7636
7637 the_player_menu.reset_state();
7638 the_player_menu.position(0, 0);
7639
7640 bool running = true;
7641 bool esc = key[KEY_ESC] || cMbtn();
7642 bool autopop = esc;
7643 do
7644 {
7645 if(reload_fonts)
7646 {
7647 init_custom_fonts();
7648 clear_bitmap(menu_bmp);
7649 broadcast_dialog_message(MSG_DRAW, 0);
7650 reload_fonts = false;
7651 }
7652 if(handle_close_btn_quit())
7653 break;
7654
7655 //update submenus
7656 {
7657 settings_menu.disable_uid(MENUID_SETTINGS_CONTROLS, replay_is_replaying());
7658 settings_menu.select_uid(MENUID_SETTINGS_CAPFPS, Throttlefps);
7659 settings_menu.select_uid(MENUID_SETTINGS_SHOWFPS, ShowFPS);
7660 settings_menu.select_uid(MENUID_SETTINGS_SHOWTIME, ShowGameTime);
7661 settings_menu.select_uid(MENUID_SETTINGS_CLICK_FREEZE, ClickToFreeze);
7662 settings_menu.select_uid(MENUID_SETTINGS_TRANSLAYERS, TransLayers);
7663 settings_menu.select_uid(MENUID_SETTINGS_NESQUIT, NESquit);
7664 settings_menu.select_uid(MENUID_SETTINGS_VOLKEYS, volkeys);
7665
7666 window_menu.select_uid(MENUID_WINDOW_LOCK_ASPECT, DragAspect);
7667 window_menu.select_uid(MENUID_WINDOW_LOCK_INTSCALE, scaleForceInteger);
7668 window_menu.select_uid(MENUID_WINDOW_SAVE_SIZE, SaveDragResize);
7669 window_menu.select_uid(MENUID_WINDOW_SAVE_POS, SaveWinPos);
7670 window_menu.select_uid(MENUID_WINDOW_STRETCH, stretchGame);
7671
7672 options_menu.select_uid(MENUID_OPTIONS_EPILEPSYPROT, epilepsyFlashReduction);
7673 options_menu.select_uid(MENUID_OPTIONS_PAUSE_BG, pause_in_background);
7674
7675 name_entry_mode_menu.select_only_index(NameEntryMode);
7676
7677 misc_menu.select_uid(MENUID_MISC_CONSOLE, console_enabled);
7678 misc_menu.select_uid(MENUID_MISC_CLEAR_CONSOLE_ON_LOAD, clearConsoleOnLoad);
7679
7680 bool nocheat = (replay_is_replaying() || !Playing
7681 || (!maxcheat && !zcheats.flags && !get_debug() && DEVLEVEL < 2 && !zqtesting_mode && !devpwd()));
7682 the_player_menu.disable_uid(MENUID_PLAYER_CHEAT, nocheat);
7683 refill_menu.disable_uid(MENUID_REFILL_ARROWS, !get_qr(qr_TRUEARROWS));
7684 cheat_menu.chop_index.reset();
7685 if(cheat < 4)
7686 cheat_menu.chop_index = cheat_menu.ind_at(MENUID_CHEAT_CHOP_L1+cheat);
7687 cheat_menu.select_uid(MENUID_CHEAT_INVULN, getClock());
7688 cheat_menu.select_uid(MENUID_CHEAT_NOCLIP, toogam);
7689 cheat_menu.select_uid(MENUID_CHEAT_IGNORESV, ignoreSideview);
7690 cheat_menu.select_uid(MENUID_CHEAT_GOFAST, gofast);
7691
7692 show_menu.select_uid(MENUID_SHOW_L0, show_layer_0);
7693 show_menu.select_uid(MENUID_SHOW_L1, show_layer_1);
7694 show_menu.select_uid(MENUID_SHOW_L2, show_layer_2);
7695 show_menu.select_uid(MENUID_SHOW_L3, show_layer_3);
7696 show_menu.select_uid(MENUID_SHOW_L4, show_layer_4);
7697 show_menu.select_uid(MENUID_SHOW_L5, show_layer_5);
7698 show_menu.select_uid(MENUID_SHOW_L6, show_layer_6);
7699 show_menu.select_uid(MENUID_SHOW_OVER, show_layer_over);
7700 show_menu.select_uid(MENUID_SHOW_PUSH, show_layer_push);
7701 show_menu.select_uid(MENUID_SHOW_SPR, show_sprites);
7702 show_menu.select_uid(MENUID_SHOW_FFC, show_ffcs);
7703 show_menu.select_uid(MENUID_SHOW_SOLIDITY, show_walkflags);
7704 show_menu.select_uid(MENUID_SHOW_SCRIPTNAME, show_ff_scripts);
7705 show_menu.select_uid(MENUID_SHOW_HITBOX, show_hitboxes);
7706 show_menu.select_uid(MENUID_SHOW_EFFECT, show_effectflags);
7707
7708 settings_menu.select_uid(MENUID_SETTINGS_HEARTBEEP, heart_beep);
7709 settings_menu.select_uid(MENUID_SETTINGS_SAVEINDICATOR, use_save_indicator);
7710
7711 replay_menu.by_uid(MENUID_REPLAY_STOP)->text = fmt::format("Stop {}",
7712 replay_get_mode() == ReplayMode::Record ? "recording" : "replaying");
7713
7714 replay_menu.select_uid(MENUID_REPLAY_RECORDNEW, zc_get_config("zeldadx", "replay_new_saves", false));
7715 #ifdef HAS_CURL
7716 replay_menu.select_uid(MENUID_REPLAY_AUTOUPLOAD, replay_upload_auto_enabled());
7717 #endif
7718 replay_menu.disable_uid(MENUID_REPLAY_STOP, !replay_is_active());
7719 replay_menu.disable_uid(MENUID_REPLAY_SAVE, replay_get_mode() != ReplayMode::Record);
7720 replay_menu.select_uid(MENUID_REPLAY_SNAP_ALL, replay_is_snapshot_all_frames());
7721
7722 snapshot_format_menu.select_only_index(SnapshotFormat);
7723 }
7724
7725 if(debug_enabled)
7726 settings_menu.select_uid(MENUID_SETTINGS_DEBUG, get_debug());
7727
7728 if(autopop)
7729 clear_keybuf();
7730 the_player_menu.run(true);
7731 if(autopop)
7732 {
7733 the_player_menu.pop_sub(0, &the_player_menu);
7734 the_player_menu.draw(screen, the_player_menu.hovered_ind());
7735 autopop = false;
7736 update_hw_screen();
7737 }
7738
7739 update_hw_screen();
7740
7741 auto mb = gui_mouse_b();
7742 if(XOR(mb, mouse_down))
7743 {
7744 if(!the_player_menu.has_mouse())
7745 if(mb)
7746 break;
7747 mouse_down = mb;
7748 }
7749
7750 if(input_idle(true) > after_time())
7751 // run Screeen Saver
7752 {
7753 // Screen saver enabled for now.
7754 clear_keybuf();
7755 Matrix(ss_speed, ss_density, 0);
7756 system_pal(true);
7757 sys_mouse();
7758 }
7759
7760 poll_keyboard();
7761 if(esc)
7762 {
7763 if(!key[KEY_ESC])
7764 esc = false;
7765 }
7766
7767 if(keypressed() && !CHECK_ALT) //System hotkeys
7768 {
7769 auto c = peekkey();
7770 bool eatkey = true;
7771 switch(c>>8)
7772 {
7773 //Spare keys used by the menu
7774 case KEY_UP:
7775 case KEY_DOWN:
7776 case KEY_LEFT:
7777 case KEY_RIGHT:
7778 eatkey = false;
7779 break;
7780 case KEY_F1:
7781 onThrottleFPS();
7782 break;
7783 case KEY_F2:
7784 onShowFPS();
7785 break;
7786 case KEY_F6:
7787 onTryQuitMenu();
7788 break;
7789 #ifndef ALLEGRO_MACOSX
7790 case KEY_F9:
7791 onReset();
7792 break;
7793 case KEY_F10:
7794 onExit();
7795 break;
7796 #else
7797 case KEY_F7:
7798 onReset();
7799 break;
7800 case KEY_F8:
7801 onExit();
7802 break;
7803 #endif
7804 case KEY_F12:
7805 onSnapshot();
7806 break;
7807 case KEY_TAB:
7808 onDebug();
7809 break;
7810 case KEY_ESC:
7811 if(!esc)
7812 running = false;
7813 break;
7814 }
7815 if(eatkey)
7816 readkey();
7817 }
7818 if(Quit || (GameFlags & GAMEFLAG_TRYQUIT))
7819 break;
7820 }
7821 while(running);
7822
7823 screen = oldscreen;
7824
7825 mouse_down=gui_mouse_b();
7826 MenuOpen = false;
7827 if(Quit)
7828 {
7829 kill_sfx();
7830 music_stop();
7831 update_hw_screen();
7832 }
7833 else
7834 {
7835 music_resume();
7836 resume_all_sfx();
7837
7838 if(rc)
7839 ringcolor(false);
7840 }
7841 exit_sys_pal();
7842
7843 eat_buttons();
7844
7845 rc=false;
7846 clear_keybuf();
7847
7848 zc_init_apply_cheat_delta();
7849 }
7850
7851 239 void fix_dialogs()
7852 {
7853 239 jwin_center_dialog(about_dlg);
7854 239 jwin_center_dialog(gamepad_dlg);
7855 239 jwin_center_dialog(credits_dlg);
7856 239 jwin_center_dialog(gamemode_dlg);
7857 239 jwin_center_dialog(getnum_dlg);
7858 239 jwin_center_dialog(goto_dlg);
7859 239 jwin_center_dialog(keyboard_control_dlg);
7860 239 jwin_center_dialog(midi_dlg);
7861 239 jwin_center_dialog(quest_dlg);
7862 239 jwin_center_dialog(scrsaver_dlg);
7863 239 jwin_center_dialog(sound_dlg);
7864 239 jwin_center_dialog(triforce_dlg);
7865 239 }
7866
7867 4255 INLINE int32_t mixvol(int32_t v1,int32_t v2)
7868 {
7869
3/4
✓ Branch 0 taken 4255 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4233 times.
✓ Branch 3 taken 22 times.
4255 return (zc_min(v1,255)*zc_min(v2,255)) >> 8;
7870 }
7871
7872 289 int32_t get_emusic_volume()
7873 {
7874 289 int32_t temp_volume = emusic_volume;
7875
2/4
✓ Branch 0 taken 289 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 289 times.
✗ Branch 3 not taken.
289 if (GameLoaded && !get_qr(qr_OLD_SCRIPT_VOLUME))
7876 temp_volume = (emusic_volume * FFCore.usr_music_volume) / 10000 / 100;
7877
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 289 times.
289 if (!zcmusic)
7878 289 return temp_volume;
7879 return (temp_volume * zcmusic->fadevolume) / 10000;
7880 289 }
7881
7882 int32_t get_zcmusicpos()
7883 {
7884 int32_t debugtracething = zcmusic_get_curpos(zcmusic);
7885 return debugtracething;
7886 return 0;
7887 }
7888
7889 void set_zcmusicpos(int32_t position)
7890 {
7891 zcmusic_set_curpos(zcmusic, position);
7892 }
7893
7894 void set_zcmusicspeed(int32_t speed)
7895 {
7896 zcmusic_set_speed(zcmusic, speed);
7897 }
7898
7899 int32_t get_zcmusiclen()
7900 {
7901 return zcmusic_get_length(zcmusic);
7902 }
7903
7904 3 void set_zcmusicloop(double start, double end)
7905 {
7906 3 zcmusic_set_loop(zcmusic, start, end);
7907 3 }
7908
7909 64156 void jukebox(int32_t index,int32_t loop)
7910 {
7911
1/2
✓ Branch 0 taken 64156 times.
✗ Branch 1 not taken.
64156 if (is_headless())
7912 64156 return;
7913
7914 music_stop();
7915
7916 if(index<0) index=MAXMIDIS-1;
7917
7918 if(index>=MAXMIDIS) index=0;
7919
7920 music_stop();
7921
7922 // Allegro's DIGMID driver (the one normally used on on Linux) gets
7923 // stuck notes when a song stops. This fixes it.
7924 if(strcmp(midi_driver->name, "DIGMID")==0)
7925 zc_set_volume(0, 0);
7926
7927 zc_set_volume(-1, mixvol(tunes[index].volume, midi_volume >>1));
7928 zc_play_midi(tunes[index].data,loop);
7929
7930 if(tunes[index].start>0)
7931 zc_midi_seek(tunes[index].start);
7932
7933 midi_loop_start = tunes[index].loop_start;
7934 midi_loop_end = tunes[index].loop_end;
7935
7936 currmidi=index;
7937 master_volume(digi_volume, midi_volume);
7938 //midi_paused=false;
7939 64156 }
7940
7941 64156 void jukebox(int32_t index)
7942 {
7943
1/2
✓ Branch 0 taken 64156 times.
✗ Branch 1 not taken.
64156 if(index<0) index=MAXMIDIS-1;
7944
7945
1/2
✓ Branch 0 taken 64156 times.
✗ Branch 1 not taken.
64156 if(index>=MAXMIDIS) index=0;
7946
7947 // do nothing if it's already playing
7948
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 64156 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
64156 if(index==currmidi && midi_pos>=0)
7949 {
7950 return;
7951 }
7952
7953 64156 jukebox(index,tunes[index].loop);
7954 64156 }
7955
7956 100 void play_DmapMusic()
7957 {
7958
1/2
✓ Branch 0 taken 100 times.
✗ Branch 1 not taken.
100 if (is_headless())
7959 100 return;
7960
7961 static char tfile[2048];
7962 static int32_t ttrack=0;
7963 bool domidi=false;
7964
7965 int32_t fadeoutframes = 0;
7966 if (zcmusic != NULL)
7967 fadeoutframes = zcmusic->fadeoutframes;
7968
7969 if(DMaps[currdmap].tmusic[0]!=0)
7970 {
7971 if(zcmusic==NULL ||
7972 strcmp(zcmusic->filename,DMaps[currdmap].tmusic)!=0 ||
7973 (zcmusic->type==ZCMF_GME && zcmusic->track != DMaps[currdmap].tmusictrack))
7974 {
7975 if (DMaps[currdmap].tmusic_xfade_in > 0 || fadeoutframes > 0)
7976 {
7977 if (play_enh_music_crossfade(DMaps[currdmap].tmusic, qstpath, DMaps[currdmap].tmusictrack, get_emusic_volume(), DMaps[currdmap].tmusic_xfade_in, fadeoutframes))
7978 {
7979 if (zcmusic != NULL)
7980 {
7981 zcmusic->fadeoutframes = DMaps[currdmap].tmusic_xfade_out;
7982 zcmusic_set_loop(zcmusic, double(DMaps[currdmap].tmusic_loop_start / 10000.0), double(DMaps[currdmap].tmusic_loop_end / 10000.0));
7983 }
7984 }
7985 }
7986 else
7987 {
7988 if (zcmusic != NULL)
7989 {
7990 zcmusic_stop(zcmusic);
7991 zcmusic_unload_file(zcmusic);
7992 zcmusic = NULL;
7993 zcmixer->newtrack = NULL;
7994 }
7995
7996 zcmusic = zcmusic_load_for_quest(DMaps[currdmap].tmusic, qstpath);
7997 zcmixer->newtrack = zcmusic;
7998
7999 if (zcmusic != NULL)
8000 {
8001 zc_stop_midi();
8002 strcpy(tfile, DMaps[currdmap].tmusic);
8003 zcmusic_play(zcmusic, emusic_volume);
8004 int32_t temptracks = 0;
8005 temptracks = zcmusic_get_tracks(zcmusic);
8006 temptracks = (temptracks < 2) ? 1 : temptracks;
8007 ttrack = vbound(DMaps[currdmap].tmusictrack, 0, temptracks - 1);
8008 zcmusic_change_track(zcmusic, ttrack);
8009 zcmusic_set_loop(zcmusic, double(DMaps[currdmap].tmusic_loop_start / 10000.0), double(DMaps[currdmap].tmusic_loop_end / 10000.0));
8010 }
8011 else
8012 {
8013 tfile[0] = 0;
8014 domidi = true;
8015 }
8016 }
8017 }
8018 }
8019 else
8020 {
8021 if (DMaps[currdmap].midi == 0 && fadeoutframes > 0 && zcmusic != NULL && strcmp(zcmusic->filename, DMaps[currdmap].tmusic) != 0)
8022 {
8023 play_enh_music_crossfade(NULL, qstpath, DMaps[currdmap].tmusictrack, get_emusic_volume(), DMaps[currdmap].tmusic_xfade_in, fadeoutframes);
8024 }
8025 else
8026 {
8027 domidi = true;
8028 }
8029 }
8030
8031 if(domidi)
8032 {
8033 int32_t m=DMaps[currdmap].midi;
8034
8035 switch(m)
8036 {
8037 case 1:
8038 jukebox(ZC_MIDI_OVERWORLD);
8039 break;
8040
8041 case 2:
8042 jukebox(ZC_MIDI_DUNGEON);
8043 break;
8044
8045 case 3:
8046 jukebox(ZC_MIDI_LEVEL9);
8047 break;
8048
8049 default:
8050 if(m>=4 && m<4+MAXCUSTOMMIDIS)
8051 jukebox(m+MIDIOFFSET_DMAP);
8052 else
8053 music_stop();
8054 }
8055 }
8056 100 }
8057
8058 34872 void playLevelMusic()
8059 {
8060
1/2
✓ Branch 0 taken 34872 times.
✗ Branch 1 not taken.
34872 if (is_headless())
8061 34872 return;
8062
8063 int32_t m=tmpscr->screen_midi;
8064
8065 switch(m)
8066 {
8067 case -2:
8068 music_stop();
8069 break;
8070
8071 case -1:
8072 play_DmapMusic();
8073 break;
8074
8075 case 1:
8076 jukebox(ZC_MIDI_OVERWORLD);
8077 break;
8078
8079 case 2:
8080 jukebox(ZC_MIDI_DUNGEON);
8081 break;
8082
8083 case 3:
8084 jukebox(ZC_MIDI_LEVEL9);
8085 break;
8086
8087 default:
8088 if(m>=4 && m<4+MAXCUSTOMMIDIS)
8089 jukebox(m+MIDIOFFSET_MAPSCR);
8090 else
8091 music_stop();
8092 }
8093 34872 }
8094
8095 4255 void master_volume(int32_t dv,int32_t mv)
8096 {
8097
7/8
✓ Branch 0 taken 2008 times.
✓ Branch 1 taken 2247 times.
✓ Branch 2 taken 1967 times.
✓ Branch 3 taken 280 times.
✓ Branch 4 taken 2247 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1967 times.
✓ Branch 7 taken 280 times.
4255 if(dv>=0) digi_volume=zc_max(zc_min(dv,255),0);
8098
8099
7/8
✓ Branch 0 taken 2004 times.
✓ Branch 1 taken 2251 times.
✓ Branch 2 taken 2000 times.
✓ Branch 3 taken 251 times.
✓ Branch 4 taken 2251 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2000 times.
✓ Branch 7 taken 251 times.
4255 if(mv>=0) midi_volume=zc_max(zc_min(mv,255),0);
8100
8101
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 4255 times.
✓ Branch 2 taken 4255 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4255 times.
4255 int32_t i = zc_min(zc_max(currmidi,0),MAXMIDIS-1);
8102 4255 int32_t temp_vol = midi_volume;
8103
2/2
✓ Branch 0 taken 4016 times.
✓ Branch 1 taken 239 times.
4255 if (!get_qr(qr_OLD_SCRIPT_VOLUME))
8104 239 temp_vol = (midi_volume * FFCore.usr_music_volume) / 10000 / 100;
8105 4255 zc_set_volume(digi_volume,mixvol(tunes[i].volume, temp_vol));
8106 4255 }
8107
8108 // array of voices, one for each sfx sample in the data file
8109 // 0+ = voice #
8110 // -1 = voice not allocated
8111 239 void Z_init_sound()
8112 {
8113
2/2
✓ Branch 0 taken 61184 times.
✓ Branch 1 taken 239 times.
61423 for(int32_t i=0; i<WAV_COUNT; i++)
8114 61184 sfx_voice[i]=-1;
8115
8116 239 const char* midis[ZC_MIDI_COUNT] = {
8117 "assets/dungeon.mid",
8118 "assets/ending.mid",
8119 "assets/gameover.mid",
8120 "assets/level9.mid",
8121 "assets/overworld.mid",
8122 "assets/title.mid",
8123 "assets/triforce.mid",
8124 };
8125
2/2
✓ Branch 0 taken 1673 times.
✓ Branch 1 taken 239 times.
1912 for(int32_t i=0; i<ZC_MIDI_COUNT; i++)
8126 {
8127 1673 tunes[i].data = load_midi(midis[i]);
8128
1/2
✓ Branch 0 taken 1673 times.
✗ Branch 1 not taken.
1673 if (!tunes[i].data)
8129 Z_error_fatal("Missing required file %s\n", midis[i]);
8130 1673 }
8131
8132
2/2
✓ Branch 0 taken 60228 times.
✓ Branch 1 taken 239 times.
60467 for(int32_t j=0; j<MAXCUSTOMMIDIS; j++)
8133 60228 tunes[ZC_MIDI_COUNT+j].data=NULL;
8134
8135 239 master_volume(digi_volume,midi_volume);
8136 239 }
8137
8138 // returns number of voices currently allocated
8139 int32_t sfx_count()
8140 {
8141 int32_t c=0;
8142
8143 for(int32_t i=0; i<WAV_COUNT; i++)
8144 if(sfx_voice[i]!=-1)
8145 ++c;
8146
8147 return c;
8148 }
8149
8150 // clean up finished samples
8151 18095007 void sfx_cleanup()
8152 {
8153
2/2
✓ Branch 0 taken 4632321792 times.
✓ Branch 1 taken 18095007 times.
4650416799 for(int32_t i=0; i<WAV_COUNT; i++)
8154
3/4
✓ Branch 0 taken 1256573 times.
✓ Branch 1 taken 4631065219 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1256573 times.
4633578365 if(sfx_voice[i]!=-1 && voice_get_position(sfx_voice[i])<0)
8155 {
8156 1256573 deallocate_voice(sfx_voice[i]);
8157 1256573 sfx_voice[i]=-1;
8158 1256573 }
8159 18095007 }
8160
8161 1256710 SAMPLE* sfx_get_sample(int32_t index)
8162 {
8163 // check index
8164
2/4
✓ Branch 0 taken 1256710 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1256710 times.
1256710 if (index<=0 || index>=WAV_COUNT)
8165 return nullptr;
8166
8167
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1256710 times.
1256710 if (sfxdat)
8168 {
8169 if (index<Z35)
8170 {
8171 return (SAMPLE*)sfxdata[index].dat;
8172 }
8173 else
8174 {
8175 return (SAMPLE*)sfxdata[Z35].dat;
8176 }
8177 }
8178 else
8179 {
8180 1256710 return &customsfxdata[index];
8181 }
8182
8183 return nullptr;
8184 1256710 }
8185
8186 // allocates a voice for the sample "wav_index" (index into zelda.dat)
8187 // if a voice is already allocated (and/or playing), then it just returns true
8188 // Returns true: voice is allocated
8189 // false: unsuccessful
8190 1846605 bool sfx_init(int32_t index)
8191 {
8192 // check index
8193
3/4
✓ Branch 0 taken 1387386 times.
✓ Branch 1 taken 459219 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1387386 times.
1846605 if(index<=0 || index>=WAV_COUNT)
8194 459219 return false;
8195
8196
2/2
✓ Branch 0 taken 130722 times.
✓ Branch 1 taken 1256664 times.
1387386 if (sfx_voice[index] == -1)
8197 {
8198 1256664 SAMPLE* sample = sfx_get_sample(index);
8199
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1256664 times.
1256664 if (!sample)
8200 return false;
8201
8202 1256664 sfx_voice[index] = allocate_voice(sample);
8203 1256664 }
8204
8205 1387386 return sfx_voice[index] != -1;
8206 1846605 }
8207
8208 int32_t sfx_get_default_freq(int32_t index)
8209 {
8210 if (sfxdat)
8211 {
8212 if (index < Z35)
8213 {
8214 return ((SAMPLE*)sfxdata[index].dat)->freq;
8215 }
8216 else
8217 {
8218 return ((SAMPLE*)sfxdata[Z35].dat)->freq;
8219 }
8220 }
8221 else
8222 {
8223 return customsfxdata[index].freq;
8224 }
8225 }
8226
8227 int32_t sfx_get_length(int32_t index)
8228 {
8229 if (sfxdat)
8230 {
8231 if (index < Z35)
8232 {
8233 return int32_t(((SAMPLE*)sfxdata[index].dat)->len);
8234 }
8235 else
8236 {
8237 return int32_t(((SAMPLE*)sfxdata[Z35].dat)->len);
8238 }
8239 }
8240 else
8241 {
8242 return int32_t(customsfxdata[index].len);
8243 }
8244 }
8245
8246 // plays an sfx sample
8247 1846605 void sfx(int32_t index,int32_t pan,bool loop, bool restart, int32_t vol, int32_t freq)
8248 {
8249
2/2
✓ Branch 0 taken 1387386 times.
✓ Branch 1 taken 459219 times.
1846605 if(!sfx_init(index))
8250 459219 return;
8251
1/2
✓ Branch 0 taken 1387386 times.
✗ Branch 1 not taken.
1387386 if (!is_headless())
8252 {
8253 voice_set_playmode(sfx_voice[index], loop ? PLAYMODE_LOOP : PLAYMODE_PLAY);
8254 voice_set_pan(sfx_voice[index], pan);
8255
8256 // Only used by ZScript currently
8257 if (freq <= -1)
8258 {
8259 freq = sfx_get_default_freq(index);
8260 }
8261 voice_set_frequency(sfx_voice[index], freq);
8262
8263 // Only used by ZScript currently
8264 int32_t temp_volume = (sfx_volume * vol) / 10000 / 100;
8265 if (GameLoaded && !get_qr(qr_OLD_SCRIPT_VOLUME))
8266 temp_volume = (temp_volume * FFCore.usr_sfx_volume) / 10000 / 100;
8267 voice_set_volume(sfx_voice[index], temp_volume);
8268
8269 int32_t pos = voice_get_position(sfx_voice[index]);
8270
8271 if (restart) voice_set_position(sfx_voice[index], 0);
8272
8273 if (pos <= 0)
8274 voice_start(sfx_voice[index]);
8275 }
8276
8277
4/4
✓ Branch 0 taken 856167 times.
✓ Branch 1 taken 531219 times.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 856157 times.
1387386 if (restart && replay_is_debug())
8278
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 856157 times.
856157 replay_step_comment(fmt::format("sfx {}", sfx_string[index]));
8279 1846605 }
8280
8281 // true if sfx is allocated
8282 198397 bool sfx_allocated(int32_t index)
8283 {
8284
3/4
✓ Branch 0 taken 33450 times.
✓ Branch 1 taken 164947 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 33450 times.
198397 return (index>0 && index<WAV_COUNT && sfx_voice[index]!=-1);
8285 }
8286
8287 // start it (in loop mode) if it's not already playing,
8288 // otherwise adjust it to play in loop mode -DD
8289 116923 void cont_sfx(int32_t index)
8290 {
8291
1/2
✓ Branch 0 taken 116923 times.
✗ Branch 1 not taken.
116923 if (is_headless())
8292 116923 return;
8293
8294 if(!sfx_init(index))
8295 {
8296 return;
8297 }
8298
8299 if(voice_get_position(sfx_voice[index])<=0)
8300 {
8301 voice_set_position(sfx_voice[index],0);
8302 voice_set_playmode(sfx_voice[index],PLAYMODE_LOOP);
8303 voice_set_volume(sfx_voice[index], sfx_volume);
8304 voice_start(sfx_voice[index]);
8305 }
8306 else
8307 {
8308 adjust_sfx(index, 128, true);
8309 }
8310 116923 }
8311
8312 // adjust parameters while playing
8313 4903 void adjust_sfx(int32_t index,int32_t pan,bool loop)
8314 {
8315
4/6
✓ Branch 0 taken 4467 times.
✓ Branch 1 taken 436 times.
✓ Branch 2 taken 4467 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4467 times.
4903 if(index<=0 || index>=WAV_COUNT || sfx_voice[index]==-1)
8316 4903 return;
8317
8318 voice_set_playmode(sfx_voice[index],loop?PLAYMODE_LOOP:PLAYMODE_PLAY);
8319 voice_set_pan(sfx_voice[index],pan);
8320 4903 }
8321
8322 // pauses a voice
8323 3223 void pause_sfx(int32_t index)
8324 {
8325
3/6
✓ Branch 0 taken 3223 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3223 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3223 times.
3223 if(index>0 && index<WAV_COUNT && sfx_voice[index]!=-1)
8326 voice_stop(sfx_voice[index]);
8327 3223 }
8328
8329 // resumes a voice
8330 1360 void resume_sfx(int32_t index)
8331 {
8332
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1360 times.
1360 if (is_headless())
8333 1360 return;
8334
8335 if(index>0 && index<WAV_COUNT && sfx_voice[index]!=-1)
8336 voice_start(sfx_voice[index]);
8337 1360 }
8338
8339 // pauses all active voices
8340 1072 void pause_all_sfx()
8341 {
8342
2/2
✓ Branch 0 taken 274432 times.
✓ Branch 1 taken 1072 times.
275504 for(int32_t i=0; i<WAV_COUNT; i++)
8343
2/2
✓ Branch 0 taken 274430 times.
✓ Branch 1 taken 2 times.
274434 if(sfx_voice[i]!=-1)
8344 2 voice_stop(sfx_voice[i]);
8345 1072 }
8346
8347 // resumes all paused voices
8348 1017 void resume_all_sfx()
8349 {
8350
2/2
✓ Branch 0 taken 260352 times.
✓ Branch 1 taken 1017 times.
261369 for(int32_t i=0; i<WAV_COUNT; i++)
8351
1/2
✓ Branch 0 taken 260352 times.
✗ Branch 1 not taken.
260352 if(sfx_voice[i]!=-1)
8352 voice_start(sfx_voice[i]);
8353 1017 }
8354
8355 // stops an sfx and deallocates the voice
8356 14472583 void stop_sfx(int32_t index)
8357 {
8358
3/4
✓ Branch 0 taken 14226260 times.
✓ Branch 1 taken 246323 times.
✓ Branch 2 taken 14226260 times.
✗ Branch 3 not taken.
14472583 if(index<=0 || index>=WAV_COUNT)
8359 246323 return;
8360
8361
2/2
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 14226227 times.
14226260 if(sfx_voice[index]!=-1)
8362 {
8363 33 deallocate_voice(sfx_voice[index]);
8364 33 sfx_voice[index]=-1;
8365 33 }
8366 14472583 }
8367
8368 // Stops SFX played by Hero's item of the given family
8369 129758 void stop_item_sfx(int32_t family)
8370 {
8371 129758 int32_t id=current_item_id(family);
8372
8373
2/2
✓ Branch 0 taken 128658 times.
✓ Branch 1 taken 1100 times.
129758 if(id<0)
8374 128658 return;
8375
8376 1100 stop_sfx(itemsbuf[id].usesound);
8377 129758 }
8378
8379 9138 void kill_sfx()
8380 {
8381
2/2
✓ Branch 0 taken 2339328 times.
✓ Branch 1 taken 9138 times.
2348466 for(int32_t i=0; i<WAV_COUNT; i++)
8382
2/2
✓ Branch 0 taken 2339270 times.
✓ Branch 1 taken 58 times.
2339386 if(sfx_voice[i]!=-1)
8383 {
8384 58 deallocate_voice(sfx_voice[i]);
8385 58 sfx_voice[i]=-1;
8386 58 }
8387 9138 }
8388
8389 1172450 int32_t pan(int32_t x)
8390 {
8391
1/4
✓ Branch 0 taken 1172450 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1172450 switch(pan_style)
8392 {
8393 case 0:
8394 return 128;
8395
8396 case 1:
8397 1172450 return vbound((x>>1)+68,0,255);
8398
8399 case 2:
8400 return vbound(((x*3)>>2)+36,0,255);
8401 }
8402
8403 return vbound(x,0,255);
8404 1172450 }
8405
8406 49791690 bool joybtn(int32_t b)
8407 {
8408
1/2
✓ Branch 0 taken 49791690 times.
✗ Branch 1 not taken.
49791690 if(b == 0)
8409 return false;
8410
1/2
✓ Branch 0 taken 49791690 times.
✗ Branch 1 not taken.
49791690 if (b-1 >= joy[joystick_index].num_buttons)
8411 49791690 return false;
8412
8413 return joy[joystick_index].button[b-1].b !=0;
8414 49791690 }
8415
8416 bool joystick(int32_t s)
8417 {
8418 if(s < 0)
8419 return false;
8420 if (s >= joy[joystick_index].num_sticks)
8421 return false;
8422
8423 for (int i = 0; i < joy[joystick_index].stick[s].num_axis; i++)
8424 {
8425 if (joy[joystick_index].stick[s].axis[i].d1 || joy[joystick_index].stick[s].axis[i].d2)
8426 return true;
8427 }
8428 return false;
8429 }
8430
8431 const char* joybtn_name(int32_t b)
8432 {
8433 if (b <= 0 || b > joy[joystick_index].num_buttons)
8434 return "";
8435
8436 return joy[joystick_index].button[b-1].name;
8437 }
8438
8439 const char* joystick_name(int32_t s)
8440 {
8441 if (s < 0 || s >= joy[joystick_index].num_sticks)
8442 return "";
8443
8444 return joy[joystick_index].stick[s].name;
8445 }
8446
8447 int32_t button_pressed()
8448 {
8449 if (joystick_index >= MAX_JOYSTICKS)
8450 return 0;
8451
8452 for(int32_t i=1; i<=joy[joystick_index].num_buttons; i++)
8453 {
8454 if(joybtn(i))
8455 return i;
8456 }
8457
8458 return 0;
8459 }
8460
8461 int32_t next_press_key();
8462
8463 int32_t next_joy_input(bool buttons)
8464 {
8465 clear_keybuf();
8466
8467 //first, we need to wait until they're pressing no buttons
8468 for(;;)
8469 {
8470 if(keypressed())
8471 {
8472 switch(readkey()>>8)
8473 {
8474 case KEY_ESC:
8475 return -1;
8476
8477 case KEY_SPACE:
8478 return 0;
8479 }
8480 }
8481
8482 poll_joystick();
8483 bool done = true;
8484
8485 if (buttons)
8486 {
8487 for(int32_t i=1; i<=joy[joystick_index].num_buttons; i++)
8488 {
8489 if(joybtn(i)) done = false;
8490 }
8491 }
8492 else
8493 {
8494 if (!gamepad_dlg_cur_joystick || !al_get_joystick_active(gamepad_dlg_cur_joystick))
8495 {
8496 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
8497 return -2;
8498 }
8499 for(int32_t i=0; i<joy[joystick_index].num_sticks; i++)
8500 {
8501 if(joystick(i)) done = false;
8502 }
8503 }
8504
8505 if(done) break;
8506 rest(1);
8507 }
8508
8509 //now, we need to wait for them to press any button
8510 for(;;)
8511 {
8512 if(keypressed())
8513 {
8514 switch(readkey()>>8)
8515 {
8516 case KEY_ESC:
8517 return -1;
8518
8519 case KEY_SPACE:
8520 return 0;
8521 }
8522 }
8523
8524 poll_joystick();
8525
8526 if (buttons)
8527 {
8528 if (!gamepad_dlg_cur_joystick || !al_get_joystick_active(gamepad_dlg_cur_joystick))
8529 {
8530 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
8531 return -2;
8532 }
8533 for(int32_t i=1; i<=joy[joystick_index].num_buttons; i++)
8534 {
8535 if(joybtn(i))
8536 return i;
8537 }
8538 }
8539 else
8540 {
8541 for(int32_t i=0; i<joy[joystick_index].num_sticks; i++)
8542 {
8543 if(joystick(i))
8544 return i;
8545 }
8546 }
8547 rest(1);
8548 }
8549 }
8550
8551 7268435 static bool rButton(bool &btn, bool &flag, bool rawbtn)
8552 {
8553
2/2
✓ Branch 0 taken 7242893 times.
✓ Branch 1 taken 25542 times.
7268435 bool ret = btn && !flag;
8554 7268435 flag = rawbtn;
8555
8556 7268435 return ret;
8557 }
8558 373283126 static bool rButton(bool &btn, bool &flag)
8559 {
8560
2/2
✓ Branch 0 taken 359525089 times.
✓ Branch 1 taken 13758037 times.
373283126 bool ret = btn && !flag;
8561 373283126 flag = btn;
8562
8563 373283126 return ret;
8564 }
8565 4574878 static bool rButtonPeek(bool btn, bool flag)
8566 {
8567
2/2
✓ Branch 0 taken 4234696 times.
✓ Branch 1 taken 340182 times.
4574878 if(!btn)
8568 {
8569 4234696 return false;
8570 }
8571
2/2
✓ Branch 0 taken 33303 times.
✓ Branch 1 taken 306879 times.
340182 else if(!flag)
8572 {
8573 33303 return true;
8574 }
8575
8576 306879 return false;
8577 4574878 }
8578
8579 // Updated only by keyboard/gamepad.
8580 // If in replay mode, this is set directly by the replay system.
8581 // This should never be read from directly - use control_state instead.
8582 bool raw_control_state[ZC_CONTROL_STATES];
8583
8584 // Every call to load_control_state (pretty much every frame) resets this to be equal to raw_control_state.
8585 // This state can drift from raw_control_state if button states are "eaten" or overriden by a script. But that only
8586 // lasts until the next call to load_control_state.
8587 bool control_state[ZC_CONTROL_STATES];
8588 bool disable_control[ZC_CONTROL_STATES];
8589 bool drunk_toggle_state[11];
8590 bool disabledKeys[127];
8591 bool KeyInput[127];
8592 bool KeyPress[127];
8593
8594 bool key_current_frame[127];
8595 bool key_previous_frame[127];
8596
8597 static bool key_system[127];
8598 static bool key_system_previous[127];
8599 static bool key_system_press[127];
8600
8601 bool button_press[ZC_CONTROL_STATES];
8602 bool button_hold[ZC_CONTROL_STATES];
8603
8604 #define STICK_1_X joy[joystick_index].stick[js_stick_1_x_stick].axis[js_stick_1_x_axis]
8605 #define STICK_1_Y joy[joystick_index].stick[js_stick_1_y_stick].axis[js_stick_1_y_axis]
8606 #define STICK_2_X joy[joystick_index].stick[js_stick_2_x_stick].axis[js_stick_2_x_axis]
8607 #define STICK_2_Y joy[joystick_index].stick[js_stick_2_y_stick].axis[js_stick_2_y_axis]
8608 #define STICK_PRECISION 56 //define your own sensitivity
8609
8610 15491246 void load_control_state()
8611 {
8612 15491246 load_control_called_this_frame = true;
8613
8614
2/2
✓ Branch 0 taken 12361614 times.
✓ Branch 1 taken 3129632 times.
15491246 if (replay_version_check(8, 11))
8615 {
8616
2/2
✓ Branch 0 taken 56333376 times.
✓ Branch 1 taken 3129632 times.
59463008 for (int i = 0; i < ZC_CONTROL_STATES; i++)
8617 56333376 down_control_states[i] = raw_control_state[i];
8618 3129632 }
8619
8620
2/2
✓ Branch 0 taken 15491225 times.
✓ Branch 1 taken 21 times.
15491246 if (!replay_is_replaying())
8621 {
8622
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
21 raw_control_state[0]=zc_getrawkey(DUkey, true)||(analog_movement ? STICK_1_Y.d1 || STICK_1_Y.pos - js_stick_1_y_offset < -STICK_PRECISION : joybtn(DUbtn));
8623
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
21 raw_control_state[1]=zc_getrawkey(DDkey, true)||(analog_movement ? STICK_1_Y.d2 || STICK_1_Y.pos - js_stick_1_y_offset > STICK_PRECISION : joybtn(DDbtn));
8624
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
21 raw_control_state[2]=zc_getrawkey(DLkey, true)||(analog_movement ? STICK_1_X.d1 || STICK_1_X.pos - js_stick_1_x_offset < -STICK_PRECISION : joybtn(DLbtn));
8625
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
21 raw_control_state[3]=zc_getrawkey(DRkey, true)||(analog_movement ? STICK_1_X.d2 || STICK_1_X.pos - js_stick_1_x_offset > STICK_PRECISION : joybtn(DRbtn));
8626
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[4]=zc_getrawkey(Akey, true)||joybtn(Abtn);
8627
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[5]=zc_getrawkey(Bkey, true)||joybtn(Bbtn);
8628
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[6]=zc_getrawkey(Skey, true)||joybtn(Sbtn);
8629
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[7]=zc_getrawkey(Lkey, true)||joybtn(Lbtn);
8630
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[8]=zc_getrawkey(Rkey, true)||joybtn(Rbtn);
8631
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[9]=zc_getrawkey(Pkey, true)||joybtn(Pbtn);
8632
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[10]=zc_getrawkey(Exkey1, true)||joybtn(Exbtn1);
8633
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[11]=zc_getrawkey(Exkey2, true)||joybtn(Exbtn2);
8634
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[12]=zc_getrawkey(Exkey3, true)||joybtn(Exbtn3);
8635
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[13]=zc_getrawkey(Exkey4, true)||joybtn(Exbtn4);
8636
8637
1/2
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
21 if(num_joysticks != 0)
8638 {
8639 raw_control_state[14] = STICK_2_Y.pos - js_stick_2_y_offset < -STICK_PRECISION;
8640 raw_control_state[15] = STICK_2_Y.pos - js_stick_2_y_offset > STICK_PRECISION;
8641 raw_control_state[16] = STICK_2_X.pos - js_stick_2_x_offset < -STICK_PRECISION;
8642 raw_control_state[17] = STICK_2_X.pos - js_stick_2_x_offset > STICK_PRECISION;
8643 }
8644 else
8645 {
8646 21 raw_control_state[14] = false;
8647 21 raw_control_state[15] = false;
8648 21 raw_control_state[16] = false;
8649 21 raw_control_state[17] = false;
8650 }
8651 21 }
8652
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 15491241 times.
15491246 if (replay_is_active())
8653 {
8654
2/2
✓ Branch 0 taken 1211700 times.
✓ Branch 1 taken 14279541 times.
15491241 if (replay_get_version() < 3)
8655 1211700 replay_poll();
8656
4/4
✓ Branch 0 taken 14279520 times.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 12518145 times.
✓ Branch 3 taken 1761375 times.
14279541 else if (replay_is_replaying() && replay_get_version() < 6)
8657 1761375 replay_peek_input();
8658
4/4
✓ Branch 0 taken 12518145 times.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 9388513 times.
✓ Branch 3 taken 3129632 times.
12518166 else if (replay_is_replaying() && replay_version_check(8, 11))
8659 3129632 replay_peek_input();
8660
2/2
✓ Branch 0 taken 14224729 times.
✓ Branch 1 taken 1266512 times.
15491241 if (replay_get_version() == 8)
8661 1266512 update_keys();
8662 15491241 }
8663
8664 // Some test replay files were made before a serious input bug was fixed, so instead
8665 // of re-doing them or tossing them out, just check for that zplay version.
8666
3/4
✓ Branch 0 taken 15491236 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 121900 times.
✓ Branch 3 taken 15369336 times.
15491246 bool botched_input = replay_is_active() && replay_get_version() != 1 && replay_get_version() < 8;
8667
2/2
✓ Branch 0 taken 278842248 times.
✓ Branch 1 taken 15491236 times.
294333484 for (int i = 0; i < ZC_CONTROL_STATES; i++)
8668 {
8669 278842248 control_state[i] = raw_control_state[i];
8670
4/4
✓ Branch 0 taken 53024022 times.
✓ Branch 1 taken 225818226 times.
✓ Branch 2 taken 2611994 times.
✓ Branch 3 taken 50412028 times.
278842248 if (botched_input && !control_state[i])
8671 50412028 down_control_states[i] = false;
8672 278842248 }
8673 15491236 bool did_bad_cutscene_btn = false;
8674
2/2
✓ Branch 0 taken 15491236 times.
✓ Branch 1 taken 278842248 times.
294333484 for(int q = 0; q < 18; ++q)
8675
4/4
✓ Branch 0 taken 13189321 times.
✓ Branch 1 taken 265652927 times.
✓ Branch 2 taken 13187738 times.
✓ Branch 3 taken 1583 times.
278843831 if(control_state[q] && !active_cutscene.can_button(q))
8676 {
8677 1583 control_state[q] = false;
8678 1583 did_bad_cutscene_btn = true;
8679 1583 }
8680
2/2
✓ Branch 0 taken 15490091 times.
✓ Branch 1 taken 1145 times.
15491236 if(did_bad_cutscene_btn)
8681 1145 active_cutscene.error();
8682
8683 15491236 button_press[0]=rButton(control_state[0],button_hold[0]);
8684 15491236 button_press[1]=rButton(control_state[1],button_hold[1]);
8685 15491236 button_press[2]=rButton(control_state[2],button_hold[2]);
8686 15491236 button_press[3]=rButton(control_state[3],button_hold[3]);
8687 15491236 button_press[4]=rButton(control_state[4],button_hold[4]);
8688 15491236 button_press[5]=rButton(control_state[5],button_hold[5]);
8689 15491236 button_press[6]=rButton(control_state[6],button_hold[6]);
8690 15491236 button_press[7]=rButton(control_state[7],button_hold[7]);
8691 15491236 button_press[8]=rButton(control_state[8],button_hold[8]);
8692 15491236 button_press[9]=rButton(control_state[9],button_hold[9]);
8693 15491236 button_press[10]=rButton(control_state[10],button_hold[10]);
8694 15491236 button_press[11]=rButton(control_state[11],button_hold[11]);
8695 15491236 button_press[12]=rButton(control_state[12],button_hold[12]);
8696 15491236 button_press[13]=rButton(control_state[13],button_hold[13]);
8697 15491236 button_press[14]=rButton(control_state[14],button_hold[14]);
8698 15491236 button_press[15]=rButton(control_state[15],button_hold[15]);
8699 15491236 button_press[16]=rButton(control_state[16],button_hold[16]);
8700 15491236 button_press[17]=rButton(control_state[17],button_hold[17]);
8701 15491236 }
8702
8703 // Returns true if any game key is pressed. This is needed because keypressed()
8704 // doesn't detect modifier keys and control_state[] can be modified by scripts.
8705 77736127 bool zc_key_pressed()
8706 //may also need to use zc_getrawkey
8707 {
8708
7/10
✓ Branch 0 taken 62773866 times.
✓ Branch 1 taken 14962261 times.
✓ Branch 2 taken 14962261 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 14962261 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 12249766 times.
✓ Branch 7 taken 12249766 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 4900347 times.
82636474 if((zc_getrawkey(DUkey, true)||(analog_movement ? STICK_1_Y.d1 || STICK_1_Y.pos - js_stick_1_y_offset< -STICK_PRECISION : joybtn(DUbtn))) ||
8709
4/6
✓ Branch 0 taken 12249766 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12249766 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9325515 times.
✓ Branch 5 taken 9325515 times.
12249766 (zc_getrawkey(DDkey, true)||(analog_movement ? STICK_1_Y.d2 || STICK_1_Y.pos - js_stick_1_y_offset > STICK_PRECISION : joybtn(DDbtn))) ||
8710
4/6
✓ Branch 0 taken 9325515 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9325515 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6178430 times.
✓ Branch 5 taken 6178430 times.
9325515 (zc_getrawkey(DLkey, true)||(analog_movement ? STICK_1_X.d1 || STICK_1_X.pos - js_stick_1_x_offset < -STICK_PRECISION : joybtn(DLbtn))) ||
8711
4/6
✓ Branch 0 taken 6178430 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6178430 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5303899 times.
✓ Branch 5 taken 5303899 times.
6178430 (zc_getrawkey(DRkey, true)||(analog_movement ? STICK_1_X.d2 || STICK_1_X.pos - js_stick_1_x_offset > STICK_PRECISION : joybtn(DRbtn))) ||
8712
1/2
✓ Branch 0 taken 5303899 times.
✗ Branch 1 not taken.
5303899 (zc_getrawkey(Akey, true)||joybtn(Abtn)) ||
8713
3/4
✓ Branch 0 taken 5118232 times.
✓ Branch 1 taken 185667 times.
✓ Branch 2 taken 5118232 times.
✗ Branch 3 not taken.
5303899 (zc_getrawkey(Bkey, true)||joybtn(Bbtn)) ||
8714
3/4
✓ Branch 0 taken 4972127 times.
✓ Branch 1 taken 146105 times.
✓ Branch 2 taken 4972127 times.
✗ Branch 3 not taken.
5118232 (zc_getrawkey(Skey, true)||joybtn(Sbtn)) ||
8715
3/4
✓ Branch 0 taken 4951257 times.
✓ Branch 1 taken 20870 times.
✓ Branch 2 taken 4951257 times.
✗ Branch 3 not taken.
4972127 (zc_getrawkey(Lkey, true)||joybtn(Lbtn)) ||
8716
3/4
✓ Branch 0 taken 4924898 times.
✓ Branch 1 taken 26359 times.
✓ Branch 2 taken 4924898 times.
✗ Branch 3 not taken.
4951257 (zc_getrawkey(Rkey, true)||joybtn(Rbtn)) ||
8717
3/4
✓ Branch 0 taken 4917613 times.
✓ Branch 1 taken 7285 times.
✓ Branch 2 taken 4917613 times.
✗ Branch 3 not taken.
4924898 (zc_getrawkey(Pkey, true)||joybtn(Pbtn)) ||
8718
3/4
✓ Branch 0 taken 4902260 times.
✓ Branch 1 taken 15353 times.
✓ Branch 2 taken 4902260 times.
✗ Branch 3 not taken.
4917613 (zc_getrawkey(Exkey1, true)||joybtn(Exbtn1)) ||
8719
3/4
✓ Branch 0 taken 4900441 times.
✓ Branch 1 taken 1819 times.
✓ Branch 2 taken 4900441 times.
✗ Branch 3 not taken.
4902260 (zc_getrawkey(Exkey2, true)||joybtn(Exbtn2)) ||
8720
3/4
✓ Branch 0 taken 4900406 times.
✓ Branch 1 taken 35 times.
✓ Branch 2 taken 4900406 times.
✗ Branch 3 not taken.
4900441 (zc_getrawkey(Exkey3, true)||joybtn(Exbtn3)) ||
8721
2/2
✓ Branch 0 taken 4900347 times.
✓ Branch 1 taken 59 times.
4900406 (zc_getrawkey(Exkey4, true)||joybtn(Exbtn4))) // Skipping joystick axes
8722 138951000 return true;
8723
8724 4900347 return false;
8725 18303615 }
8726
8727 294499884 bool getInput(int32_t btn, bool press, bool drunk, bool ignoreDisable, bool eatEntirely, bool peek)
8728 {
8729 294499884 bool ret = false, drunkstate = false, rawret = false;;
8730 294499884 bool* flag = &down_control_states[btn];
8731
2/7
✓ Branch 0 taken 276177473 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 18322411 times.
294499884 switch(btn)
8732 {
8733 case btnF12:
8734 ret = zc_getkey(KEY_F12, ignoreDisable);
8735 rawret = zc_getrawkey(KEY_F12, ignoreDisable);
8736 eatEntirely = false;
8737 break;
8738 case btnF11:
8739 ret = zc_getkey(KEY_F11, ignoreDisable);
8740 rawret = zc_getrawkey(KEY_F11, ignoreDisable);
8741 eatEntirely = false;
8742 break;
8743 case btnF5:
8744 ret = zc_getkey(KEY_F5, ignoreDisable);
8745 rawret = zc_getrawkey(KEY_F5, ignoreDisable);
8746 eatEntirely = false;
8747 break;
8748 case btnQ:
8749 ret = zc_getkey(KEY_Q, ignoreDisable);
8750 rawret = zc_getrawkey(KEY_Q, ignoreDisable);
8751 eatEntirely = false;
8752 break;
8753 case btnI:
8754 ret = zc_getkey(KEY_I, ignoreDisable);
8755 rawret = zc_getrawkey(KEY_I, ignoreDisable);
8756 eatEntirely = false;
8757 break;
8758 case btnM:
8759
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18322411 times.
18322411 if(FFCore.kb_typing_mode) return false;
8760 18322411 rawret = ret = zc_getrawkey(KEY_ESC, ignoreDisable);
8761 18322411 eatEntirely = false;
8762 18322411 break;
8763 default: //control_state[] index
8764
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 276177473 times.
276177473 if(FFCore.kb_typing_mode) return false;
8765
6/6
✓ Branch 0 taken 274799535 times.
✓ Branch 1 taken 1377938 times.
✓ Branch 2 taken 16486183 times.
✓ Branch 3 taken 258313352 times.
✓ Branch 4 taken 16486030 times.
✓ Branch 5 taken 153 times.
276177473 if(!ignoreDisable && get_qr(qr_FIXDRUNKINPUTS) && disable_control[btn]) drunk = false;
8766
2/2
✓ Branch 0 taken 15721713 times.
✓ Branch 1 taken 260455607 times.
276177320 else if(btn<11) drunkstate = drunk_toggle_state[btn];
8767
4/4
✓ Branch 0 taken 245411576 times.
✓ Branch 1 taken 30765897 times.
✓ Branch 2 taken 7154 times.
✓ Branch 3 taken 30758743 times.
306943370 ret = control_state[btn] && (ignoreDisable || !disable_control[btn]);
8768 276177473 rawret = raw_control_state[btn];
8769 276177473 }
8770
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 294499884 times.
294499884 assert(flag);
8771
2/2
✓ Branch 0 taken 188215693 times.
✓ Branch 1 taken 106284191 times.
294499884 if(press)
8772 {
8773
2/2
✓ Branch 0 taken 4574878 times.
✓ Branch 1 taken 101709313 times.
106284191 if(peek)
8774 4574878 ret = rButtonPeek(ret, *flag);
8775
2/2
✓ Branch 0 taken 94440878 times.
✓ Branch 1 taken 7268435 times.
101709313 else if(get_qr(qr_BROKEN_INPUT_DOWN_STATE)) ret = rButton(ret, *flag);
8776 7268435 else ret = rButton(ret, *flag, rawret);
8777 106284191 }
8778
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 294499884 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
294499884 if(eatEntirely && ret) control_state[btn] = false;
8779
4/4
✓ Branch 0 taken 220040341 times.
✓ Branch 1 taken 74459543 times.
✓ Branch 2 taken 220040260 times.
✓ Branch 3 taken 81 times.
294499884 if(drunk && drunkstate) ret = !ret;
8780 294499884 return ret;
8781 294499884 }
8782
8783 14789901 byte getIntBtnInput(byte intbtn, bool press, bool drunk, bool ignoreDisable, bool eatEntirely, bool peek)
8784 {
8785 14789901 byte ret = 0;
8786
2/2
✓ Branch 0 taken 10438455 times.
✓ Branch 1 taken 4351446 times.
14789901 if(intbtn & INT_BTN_A) ret |= getInput(btnA, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_A : 0;
8787
2/2
✓ Branch 0 taken 14582672 times.
✓ Branch 1 taken 207229 times.
14789901 if(intbtn & INT_BTN_B) ret |= getInput(btnB, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_B : 0;
8788
2/2
✓ Branch 0 taken 14583119 times.
✓ Branch 1 taken 206782 times.
14789901 if(intbtn & INT_BTN_L) ret |= getInput(btnL, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_L : 0;
8789
2/2
✓ Branch 0 taken 14583119 times.
✓ Branch 1 taken 206782 times.
14789901 if(intbtn & INT_BTN_R) ret |= getInput(btnR, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_R : 0;
8790
2/2
✓ Branch 0 taken 14583119 times.
✓ Branch 1 taken 206782 times.
14789901 if(intbtn & INT_BTN_EX1) ret |= getInput(btnEx1, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_EX1 : 0;
8791
2/2
✓ Branch 0 taken 14583119 times.
✓ Branch 1 taken 206782 times.
14789901 if(intbtn & INT_BTN_EX2) ret |= getInput(btnEx2, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_EX2 : 0;
8792
2/2
✓ Branch 0 taken 14583119 times.
✓ Branch 1 taken 206782 times.
14789901 if(intbtn & INT_BTN_EX3) ret |= getInput(btnEx3, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_EX3 : 0;
8793
2/2
✓ Branch 0 taken 14583004 times.
✓ Branch 1 taken 206897 times.
14789901 if(intbtn & INT_BTN_EX4) ret |= getInput(btnEx4, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_EX4 : 0;
8794 14789901 return ret; //No early return, to make sure all button presses are eaten that should be! -Em
8795 }
8796
8797 7010 byte checkIntBtnVal(byte intbtn, byte vals)
8798 {
8799 7010 return intbtn&vals;
8800 }
8801
8802 3708454 bool Up()
8803 {
8804 3708454 return getInput(btnUp);
8805 }
8806 726512 bool Down()
8807 {
8808 726512 return getInput(btnDown);
8809 }
8810 979535 bool Left()
8811 {
8812 979535 return getInput(btnLeft);
8813 }
8814 1040252 bool Right()
8815 {
8816 1040252 return getInput(btnRight);
8817 }
8818 532139 bool cAbtn()
8819 {
8820 532139 return getInput(btnA);
8821 }
8822 3306978 bool cBbtn()
8823 {
8824 3306978 return getInput(btnB);
8825 }
8826 bool cSbtn()
8827 {
8828 return getInput(btnS);
8829 }
8830 208608 bool cLbtn()
8831 {
8832 208608 return getInput(btnL);
8833 }
8834 208608 bool cRbtn()
8835 {
8836 208608 return getInput(btnR);
8837 }
8838 bool cPbtn()
8839 {
8840 return getInput(btnP);
8841 }
8842 bool cEx1btn()
8843 {
8844 return getInput(btnEx1);
8845 }
8846 bool cEx2btn()
8847 {
8848 return getInput(btnEx2);
8849 }
8850 bool cEx3btn()
8851 {
8852 return getInput(btnEx3);
8853 }
8854 bool cEx4btn()
8855 {
8856 return getInput(btnEx4);
8857 }
8858 bool AxisUp()
8859 {
8860 return getInput(btnAxisUp);
8861 }
8862 bool AxisDown()
8863 {
8864 return getInput(btnAxisDown);
8865 }
8866 bool AxisLeft()
8867 {
8868 return getInput(btnAxisLeft);
8869 }
8870 bool AxisRight()
8871 {
8872 return getInput(btnAxisRight);
8873 }
8874
8875 bool cMbtn()
8876 {
8877 return getInput(btnM);
8878 }
8879 bool cF12()
8880 {
8881 return getInput(btnF12);
8882 }
8883 bool cF11()
8884 {
8885 return getInput(btnF11);
8886 }
8887 bool cF5()
8888 {
8889 return getInput(btnF5);
8890 }
8891 bool cQ()
8892 {
8893 return getInput(btnQ);
8894 }
8895 bool cI()
8896 {
8897 return getInput(btnI);
8898 }
8899
8900 208304 bool rUp()
8901 {
8902 208304 return getInput(btnUp, true);
8903 }
8904 208096 bool rDown()
8905 {
8906 208096 return getInput(btnDown, true);
8907 }
8908 207900 bool rLeft()
8909 {
8910 207900 return getInput(btnLeft, true);
8911 }
8912 207171 bool rRight()
8913 {
8914 207171 return getInput(btnRight, true);
8915 }
8916 6570 bool rAbtn()
8917 {
8918 6570 return getInput(btnA, true);
8919 }
8920 4619 bool rBbtn()
8921 {
8922 4619 return getInput(btnB, true);
8923 }
8924 14360598 bool rSbtn()
8925 {
8926 14360598 return getInput(btnS, true);
8927 }
8928 18303615 bool rMbtn()
8929 {
8930 18303615 return getInput(btnM, true);
8931 }
8932 185250 bool rLbtn()
8933 {
8934 185250 return getInput(btnL, true);
8935 }
8936 185245 bool rRbtn()
8937 {
8938 185245 return getInput(btnR, true);
8939 }
8940 14361331 bool rPbtn()
8941 {
8942 14361331 return getInput(btnP, true);
8943 }
8944 bool rEx1btn()
8945 {
8946 return getInput(btnEx1, true);
8947 }
8948 bool rEx2btn()
8949 {
8950 return getInput(btnEx2, true);
8951 }
8952 195896 bool rEx3btn()
8953 {
8954 195896 return getInput(btnEx3, true);
8955 }
8956 195896 bool rEx4btn()
8957 {
8958 195896 return getInput(btnEx4, true);
8959 }
8960 bool rAxisUp()
8961 {
8962 return getInput(btnAxisUp, true);
8963 }
8964 bool rAxisDown()
8965 {
8966 return getInput(btnAxisDown, true);
8967 }
8968 bool rAxisLeft()
8969 {
8970 return getInput(btnAxisLeft, true);
8971 }
8972 bool rAxisRight()
8973 {
8974 return getInput(btnAxisRight, true);
8975 }
8976
8977 bool rF11()
8978 {
8979 return getInput(btnF11, true);
8980 }
8981 bool rQ()
8982 {
8983 return getInput(btnQ, true);
8984 }
8985 bool rI()
8986 {
8987 return getInput(btnI, true);
8988 }
8989
8990 36567484 bool DrunkUp()
8991 {
8992 36567484 return getInput(btnUp, false, true);
8993 }
8994 33370273 bool DrunkDown()
8995 {
8996 33370273 return getInput(btnDown, false, true);
8997 }
8998 19572047 bool DrunkLeft()
8999 {
9000 19572047 return getInput(btnLeft, false, true);
9001 }
9002 16652889 bool DrunkRight()
9003 {
9004 16652889 return getInput(btnRight, false, true);
9005 }
9006 15765524 bool DrunkcAbtn()
9007 {
9008 15765524 return getInput(btnA, false, true);
9009 }
9010 15202210 bool DrunkcBbtn()
9011 {
9012 15202210 return getInput(btnB, false, true);
9013 }
9014 14152538 bool DrunkcEx1btn()
9015 {
9016 14152538 return getInput(btnEx1, false, true);
9017 }
9018 14151170 bool DrunkcEx2btn()
9019 {
9020 14151170 return getInput(btnEx2, false, true);
9021 }
9022 bool DrunkcSbtn()
9023 {
9024 return getInput(btnS, false, true);
9025 }
9026 bool DrunkcMbtn()
9027 {
9028 return getInput(btnM, false, true);
9029 }
9030 bool DrunkcLbtn()
9031 {
9032 return getInput(btnL, false, true);
9033 }
9034 bool DrunkcRbtn()
9035 {
9036 return getInput(btnR, false, true);
9037 }
9038 bool DrunkcPbtn()
9039 {
9040 return getInput(btnP, false, true);
9041 }
9042
9043 bool DrunkrUp()
9044 {
9045 return getInput(btnUp, true, true);
9046 }
9047 bool DrunkrDown()
9048 {
9049 return getInput(btnDown, true, true);
9050 }
9051 bool DrunkrLeft()
9052 {
9053 return getInput(btnLeft, true, true);
9054 }
9055 bool DrunkrRight()
9056 {
9057 return getInput(btnRight, true, true);
9058 }
9059 11824896 bool DrunkrAbtn()
9060 {
9061 11824896 return getInput(btnA, true, true);
9062 }
9063 11853428 bool DrunkrBbtn()
9064 {
9065 11853428 return getInput(btnB, true, true);
9066 }
9067 502081 bool DrunkrEx1btn()
9068 {
9069 502081 return getInput(btnEx1, true, true);
9070 }
9071 501902 bool DrunkrEx2btn()
9072 {
9073 501902 return getInput(btnEx2, true, true);
9074 }
9075 bool DrunkrEx3btn()
9076 {
9077 return getInput(btnEx3, true, true);
9078 }
9079 bool DrunkrEx4btn()
9080 {
9081 return getInput(btnEx4, true, true);
9082 }
9083 bool DrunkrSbtn()
9084 {
9085 return getInput(btnS, true, true);
9086 }
9087 bool DrunkrMbtn()
9088 {
9089 return getInput(btnM, true, true);
9090 }
9091 12890241 bool DrunkrLbtn()
9092 {
9093 12890241 return getInput(btnL, true, true);
9094 }
9095 12884936 bool DrunkrRbtn()
9096 {
9097 12884936 return getInput(btnR, true, true);
9098 }
9099 bool DrunkrPbtn()
9100 {
9101 return getInput(btnP, true, true);
9102 }
9103
9104 18796 void eat_buttons()
9105 {
9106 18796 getInput(btnA, true, false, true);
9107 18796 getInput(btnB, true, false, true);
9108 18796 getInput(btnS, true, false, true);
9109 18796 getInput(btnM, true, false, true);
9110 18796 getInput(btnL, true, false, true);
9111 18796 getInput(btnR, true, false, true);
9112 18796 getInput(btnP, true, false, true);
9113 18796 getInput(btnEx1, true, false, true);
9114 18796 getInput(btnEx2, true, false, true);
9115 18796 getInput(btnEx3, true, false, true);
9116 18796 getInput(btnEx4, true, false, true);
9117 18796 }
9118
9119 // Is true for the _first frame_ of a key press.
9120 // But! it is possible that a script manually sets the value of KeyPress,
9121 // in which case it will be restored to the "true" value based on `key_current_frame`
9122 // and `key_previous_frame` on the next frame.
9123 55 bool zc_readkey(int32_t k, bool ignoreDisable)
9124 {
9125
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55 times.
55 if(ignoreDisable) return KeyPress[k];
9126
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55 times.
55 switch(k)
9127 {
9128 case KEY_F7:
9129 case KEY_F8:
9130 case KEY_F9:
9131 return KeyPress[k];
9132
9133 default:
9134
2/2
✓ Branch 0 taken 45 times.
✓ Branch 1 taken 10 times.
55 return KeyPress[k] && !disabledKeys[k];
9135 }
9136 55 }
9137
9138 // Is true for _every frame_ a key is held down.
9139 // But! it is possible that a script manually sets the value of KeyInput,
9140 // in which case it will be restored to the "true" value based on `key_current_frame`
9141 // on the next frame.
9142 bool zc_getkey(int32_t k, bool ignoreDisable)
9143 {
9144 if(ignoreDisable) return KeyInput[k];
9145 switch(k)
9146 {
9147 case KEY_F7:
9148 case KEY_F8:
9149 case KEY_F9:
9150 return KeyInput[k];
9151
9152 default:
9153 return KeyInput[k] && !disabledKeys[k];
9154 }
9155 }
9156
9157 // Reads (and then clears) the current frame key state directly.
9158 // Scripts can also modify `key_current_frame`.
9159 916 bool zc_readrawkey(int32_t k, bool ignoreDisable)
9160 {
9161
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 914 times.
916 if(zc_getrawkey(k, ignoreDisable))
9162 {
9163 2 _key[k]=key[k]=key_current_frame[k]=0;
9164 2 return true;
9165 }
9166 914 _key[k]=key[k]=key_current_frame[k]=0;
9167 914 return false;
9168 916 }
9169
9170 // Reads the current frame key state directly.
9171 // Scripts can also modify `key_current_frame`.
9172 124234341 bool zc_getrawkey(int32_t k, bool ignoreDisable)
9173 {
9174
2/2
✓ Branch 0 taken 105930616 times.
✓ Branch 1 taken 18303725 times.
124234341 if(ignoreDisable) return key_current_frame[k];
9175
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18303725 times.
18303725 switch(k)
9176 {
9177 case KEY_F7:
9178 case KEY_F8:
9179 case KEY_F9:
9180 return key_current_frame[k];
9181
9182 default:
9183
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18303725 times.
18303725 return key_current_frame[k] && !disabledKeys[k];
9184 }
9185 124234341 }
9186
9187 // Only used for a handful of keys, like tilde and Function keys.
9188 // This state is never read within the game.
9189 // It exists so that all keyboard input still functions during replay,
9190 // without inadvertently doing things like toggling throttling if the player
9191 // presses ~
9192 bool zc_get_system_key(int32_t k)
9193 {
9194 return key_system[k];
9195 }
9196
9197 // True for the _first_ frame of a key press.
9198 164732535 bool zc_read_system_key(int32_t k)
9199 {
9200 164732535 return key_system_press[k];
9201 }
9202
9203 2324559105 bool is_system_key(int32_t k)
9204 {
9205
2/2
✓ Branch 0 taken 2159826570 times.
✓ Branch 1 taken 164732535 times.
2324559105 switch (k)
9206 {
9207 case KEY_BACKQUOTE:
9208 case KEY_CLOSEBRACE:
9209 case KEY_END:
9210 case KEY_HOME:
9211 case KEY_OPENBRACE:
9212 case KEY_PGDN:
9213 case KEY_PGUP:
9214 case KEY_TAB:
9215 case KEY_TILDE:
9216 164732535 return true;
9217 }
9218 2159826570 return is_Fkey(k);
9219 2324559105 }
9220
9221 18303615 void update_system_keys()
9222 {
9223
2/2
✓ Branch 0 taken 2324559105 times.
✓ Branch 1 taken 18303615 times.
2342862720 for (int32_t q = 0; q < 127; ++q)
9224 {
9225
2/2
✓ Branch 0 taken 384375915 times.
✓ Branch 1 taken 1940183190 times.
2324559105 if (!is_system_key(q))
9226 1940183190 continue;
9227
9228 384375915 key_system[q] = key[q];
9229
1/2
✓ Branch 0 taken 384375915 times.
✗ Branch 1 not taken.
384375915 key_system_press[q] = key_system[q] && !key_system_previous[q];
9230 384375915 key_system_previous[q] = key_system[q];
9231 384375915 }
9232 18303615 }
9233
9234 19570127 void update_keys()
9235 {
9236
2/2
✓ Branch 0 taken 2485406129 times.
✓ Branch 1 taken 19570127 times.
2504976256 for (int32_t q = 0; q < 127; ++q)
9237 {
9238 // When replaying, replay.cpp takes care of updating `key_current_frame`.
9239
2/2
✓ Branch 0 taken 2485393429 times.
✓ Branch 1 taken 12700 times.
2485406129 if (!replay_is_replaying())
9240 12700 key_current_frame[q] = key[q];
9241
9242
2/2
✓ Branch 0 taken 2466316931 times.
✓ Branch 1 taken 19089198 times.
2485406129 KeyPress[q] = key_current_frame[q] && !key_previous_frame[q];
9243 2485406129 KeyInput[q] = key_current_frame[q];
9244 2485406129 key_previous_frame[q] = key_current_frame[q];
9245 2485406129 }
9246 19570127 }
9247
9248 bool zc_disablekey(int32_t k, bool val)
9249 {
9250 switch(k)
9251 {
9252 case KEY_F7:
9253 case KEY_F8:
9254 case KEY_F9:
9255 return false;
9256
9257 default:
9258 disabledKeys[k] = val;
9259 return true;
9260 }
9261 }
9262
9263 void zc_putpixel(int32_t layer, int32_t x, int32_t y, int32_t cset, int32_t color, int32_t timer)
9264 {
9265 timer=timer;
9266 particles.add(new particle(zfix(x), zfix(y), layer, cset, color));
9267 }
9268